/**** hasOwnProperty方法被用做一个过滤器去避开for in语句中的一个隐患就是 原型中的属性*/
function hasOwnProperty1(){var name;var context = {name : "song",age : 14,address : "shanghai"};/*** Object.create()创建一个使用原对象作为其原型的新对象。*/var another_object = Object.create(context);another_object.username = "root";another_object.port = 50;document.writeln(another_object.name); // song 原型连接只有在检索值的时候才被用到document.writeln(another_object.port); // 50another_object.age = 30;document.writeln(another_object.age); // 30document.writeln(context.age); // 14 原型连接在更新时不起作用,当我们在对某个对象做修改的时,不会触及对象的原型
}
详细解决方案
js hasOwnProperty
热度:26 发布时间:2023-10-08 20:32:08.0