hasOwnProperty
谁能启发我,和有什么区别
propertyIsEnumerable
:
function f(){
this.a = 1;
this.b = 2;
this.c = function(){}
}
f.prototype = {
d : 3,
e : 4,
g : function(){}
}
//creating the instance of an object:
var o = new f();
//And here I can't see difference.
//In my opinion they are doing the same thing
console.log("o.hasOwnProperty('a'):", o.hasOwnProperty('a')); //true
console.log("o.hasOwnProperty('b'):", o.hasOwnProperty('b')); //true
console.log("o.hasOwnProperty('c'):", o.hasOwnProperty('c')); //true
console.log("o.hasOwnProperty('d'):", o.hasOwnProperty('d')); //false
console.log("o.hasOwnProperty('e'):", o.hasOwnProperty('e')); //false
console.log("o.hasOwnProperty('g'):", o.hasOwnProperty('g')); //false
console.log("o.propertyIsEnumerable('a')", o.propertyIsEnumerable('a')); //true
console.log("o.propertyIsEnumerable('b')", o.propertyIsEnumerable('b')); //true
console.log("o.propertyIsEnumerable('c')", o.propertyIsEnumerable('c')); //true
console.log("o.propertyIsEnumerable('d')", o.propertyIsEnumerable('d')); //false
console.log("o.propertyIsEnumerable('e')", o.propertyIsEnumerable('e')); //false
console.log("o.propertyIsEnumerable('g')", o.propertyIsEnumerable('g')); //false
如我错了请纠正我