bất cứ ai có thể soi sáng cho tôi, sự khác biệt giữa hasOwnProperty và propertyIsEnumerable là gì:hasOwnProperty vs propertyIsEnumerable
function f(){
this.a = 1;
this.b = 2;
this.c = function(){}
}
f.prototype = {
d : 3,
e : 4,
g : function(){}
}
tạo ra thể hiện của một đối tượng:
var o = new f();
Và ở đây tôi không thể nhìn thấy sự khác biệt . Theo tôi họ đang làm điều tương tự
o.hasOwnProperty('a'); //true
o.hasOwnProperty('b'); //true
o.hasOwnProperty('c'); //true
o.hasOwnProperty('d'); //false
o.hasOwnProperty('e'); //false
o.hasOwnProperty('g'); //false
o.propertyIsEnumerable('a'); //true
o.propertyIsEnumerable('b'); //true
o.propertyIsEnumerable('c'); //true
o.propertyIsEnumerable('d'); //false
o.propertyIsEnumerable('e'); //false
o.propertyIsEnumerable('g'); //false
phải cho tôi nếu tôi sai
lời giải thích này là rõ ràng hơn so với câu trả lời chấp nhận. – mareoraft