javascript 检查方法对象中是否存在道具。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 检查方法对象中是否存在道具。相关的知识,希望对你有一定的参考价值。

var myObject = {
	a: 2
};

/* in will check the prop's existence in both of object and high level of the [[prototype]] chain object travesal. */
("a" in myObject);	            // true
("b" in myObject);              // false

/* hasOwnProperty will check the prop's existence in the object only. */
myObject.hasOwnProperty( "a" );	// true
myObject.hasOwnProperty( "b" );	// false

以上是关于javascript 检查方法对象中是否存在道具。的主要内容,如果未能解决你的问题,请参考以下文章