您的位置:首页 > Web前端 > JavaScript

js 用 hasOwnProperty() 判定属性是来自该对象成员,还是原型链

2014-03-12 14:35 351 查看
var People=function(){
this.name='liujinyu';
};

People.prototype={
age:24,
add:function(){},
}

var p1 = new People();

for(n in p1){
document.write(n+":"+p1
+" / "+p1.hasOwnProperty(n));
document.write("<br />");
}
  //name true
  //age false
  //add false
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐