js中propertyIsEnumerable()方法使用介绍
2016-08-11 10:39
579 查看
javascript的propertyIsEnumerable()方法使用介绍
概述
propertyIsEnumerable()用来检测属性是否属于某个对象的,如果检测到了,返回true,否则false语法
obj.propertyIsEnumerable("属性名");
描述
每个对象都有propertyIsEnumerable()方法,这个方法可以判断出指定的属性是否可枚举。这个属性必须属于实例的,并且不属于原型。
这个属性必须是可枚举的,也就是自定义的属性。
如果对象没有指定的属性,该方法返回false
如果符合1和2两个要求,就会返回true.
可枚举: 如果一个属性可以使用for in
能遍历出,就是可枚举的。
实例
下面例子使用propertyIsEnumerable()方法判断实例属性和原型属性function Person(){ this.name="我是实例属性"; this.age=19; } var p=new Person(); console.log(p.propertyIsEnumerable("name")); //true Person.prototype.prop="我是原型属性";//添加一个原型属性 console.log(p.propertyIsEnumerable("prop"));//false prop是继承自原型上的属性,所以返回的是false for(var k in p){ console.log(k+","+p[k]);//name,我是实例属性 age,19 prop,我是原型属性 }
相关文章推荐
- javascript的propertyIsEnumerable()方法使用介绍
- javascript的propertyIsEnumerable()方法使用介绍
- javascript的propertyIsEnumerable()方法使用介绍
- javascript的propertyIsEnumerable()方法使用介绍
- js中的hasOwnProperty和isPrototypeOf方法使用实例
- js中的hasOwnProperty和isPrototypeOf方法使用实例
- js属性对象的propertyIsEnumerable方法
- js中的hasOwnProperty和isPrototypeOf方法使用实例
- js中的hasOwnProperty和isPrototypeOf方法使用实例
- [js方法pk]之instanceof() vs isPrototypeOf() hasOwnProperty() vs propertyIsEnumerable()
- js中的hasOwnProperty和isPrototypeOf方法使用实例
- js中的hasOwnProperty和isPrototypeOf方法使用实例
- js中的hasOwnProperty和isPrototypeOf方法使用实例
- js中的hasOwnProperty和isPrototypeOf方法
- Js中使用hasOwnProperty方法检索ajax响应对象的例子
- node.js中的buffer.Buffer.isEncoding方法使用说明
- AMD异步模块定义介绍和Require.js中使用jQuery及jQuery插件的方法
- js中的replace方法使用介绍
- JS教程:window.location使用方法的区别介绍
- js中push和join方法使用介绍