1.Object.keys(..)会返回一个数组,蕴含所有可枚举属性( enumerable: true)
2.Object.getOwnPropertyNames(...)会返回一个数组,蕴含所有属性,无论它们是否可枚举
注:Object.keys(..)和Object.getOwnPropertyNames(..)都只会查找对象间接蕴含的属性。
3.in操作符会查看属性是否在对象及其[[Prototype]]原型链中
4.hasOwnProperty(..)只会查看属性是否在对象中,不会查看[[Prototype]]链
var Obj = { name: 'mini', age: 3, show: function () { console.log(this.name + " is " + this.age); } } //MyObj 继承obj, prototype指向Obj var myObject = Object.create(Obj, { like: { value: "fish", // 初始化赋值 writable: true, // 是否是可改写的 configurable: true, // 是否可能删除,是否可能被批改 enumerable: true //是否能够用for in 进行枚举 }, hate: { configurable: true, get: function () { console.log(111); return "mouse" }, // get对象hate属性时触发的办法 set: function (value) { // set对象hate属性时触发的办法 console.log(value, 2222); return value; } } }); console.log("like" in myObject); // true console.log("age" in myObject); // true console.log(myObject.hasOwnProperty("like")) // true console.log(myObject.hasOwnProperty("age")); // false