root@test:~# node test.js
100
300
true
100
true
100
root@test:~# cat test.js
function Test(){
}
Test.prototype.v = 100;
var t = new Test();
console.log(t.v);
t.v = 300;
console.log(t.v);
console.log(delete t.v);
console.log(t.v);
console.log(delete t.v);
console.log(t.v);
If a property with the same name exists on the object's prototype chain, then, after deletion, the object will use the property from the prototype chain (in other words, delete only has an effect on own properties).
1
crazyxhz 2017-07-05 22:02:41 +08:00
有啥问题?
delete:Return value true for all cases except when the property is an own non-configurable property, in which case, false is returned in non-strict mode. |
2
gongbaodd 2017-07-06 10:28:31 +08:00
没毛病,基于原型嘛
|
3
xss OP |