Javascript-检测参数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Javascript-检测参数相关的知识,希望对你有一定的参考价值。
// Detecting the existence of a parameter /* Example 1: The in operator Detect whether there is a "myparameter" member in the "oArg" object: */ var myparameter = 'myparameter' in oArg? oArg.myparameter : ""; /* Example 2: The typeof operator Detect whether type of oArg.myparameter is not "undefined': */ var myparameter = typeof oArg.myparameter != 'undefined'? oArg.myparameter : ""; /* Example 2.1: The typeof operator version 2 Assuming parameter is a string, detect whether type of oArg.myparameter is "string": */ var myparameter = typeof oArg.myparameter == 'string'? oArg.myparameter : ""; /* Example 3: Autocasting Assign the value of oArg.myparameter to variable "myparameter" if it casts to true: */ var myparameter = oArg.myparameter || "";
以上是关于Javascript-检测参数的主要内容,如果未能解决你的问题,请参考以下文章
JavaScript函数的默认参数(default parameter)