/***
* 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); // 50
another_object.age = 30;
document.writeln(another_object.age); // 30
document.writeln(context.age); // 14
原型连接在更新时不起作用,当我们在对某个对象做修改的时,不会触及对象的原型
}
js hasOwnProperty
猜你喜欢
转载自blog.csdn.net/qq_34579060/article/details/80942341
今日推荐
周排行