最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

JS Testing Properties 判斷屬性是否在對(duì)象里的方法

 更新時(shí)間:2017年10月01日 09:05:01   作者:流暢的心情  
下面小編就為大家?guī)?lái)一篇JS Testing Properties 判斷屬性是否在對(duì)象里的方法。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧

Testing Properties

To check whether an object has a property with a given name. You can do this with the in operator, with the hasOwnProperty() and propertyIsEnumerable() methods,

在JS中判斷一個(gè)對(duì)象是否包含某個(gè)屬性,可以使用 in,hasOwnProperty() and propertyIsEnumerable()

or simply by querying the property.

或者直接使用查詢屬性。

in--It returns true if the object has an own property or an inherited property 

用In,當(dāng)前對(duì)象存在或者有繼承,就返回true。

hasOwnProperty() --To test whether that object has an own property with the given name. It returns false for inherited properties

用hasOwnProperty() ,只關(guān)心本對(duì)象,不關(guān)心繼承來(lái)的屬性。

propertyIsEnumerable()--The propertyIsEnumerable() refines the hasOwnProperty() test. It returns true only if the named property is an own property and its enumerable attribute is true.

用propertyIsEnumerable() ,和hasOwnProperty() 這個(gè)類似,只是要求 屬性可枚舉。

 Instead of using the in operator  it is often sufficient to simply query the property and use !== to make sure it is not undefined

 o.x !== undefined; // true: o has a property x

替代In的最簡(jiǎn)單辦法就是  query   +    !==Undefined

in can distinguish between properties that do not exist and properties that exist but have been set to undefined.

in 有個(gè)好處就是還能區(qū)分到底屬性的值是undefined還是本身就不存在。

以上這篇JS Testing Properties 判斷屬性是否在對(duì)象里的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論

广灵县| 于都县| 沧源| 富民县| 岱山县| 和平县| 新乡县| 齐河县| 宣化县| 英山县| 加查县| 浙江省| 吉水县| 本溪| 云梦县| 芷江| 资溪县| 南皮县| 临澧县| 灯塔市| 含山县| 监利县| 大理市| 陵川县| 巴塘县| 台东县| 蓝山县| 澄迈县| 龙州县| 十堰市| 新化县| 黄石市| 长子县| 乐都县| 宁夏| 新巴尔虎左旗| 临桂县| 敦煌市| 德钦县| 新昌县| 连平县|