参考yt_9119的百度知道,网址为:http://zhidao.baidu.com/question/175442954926209444.html?fr=iks&word=js+hasownproperty&ie=gbk
//hasOwnProperty是用来判断一个对象是否具有你给出名称的属性和对象,
//不过此方法无法查出其原型链中是否具有该属性,该属性必须为其本身的一个成员var obj={
a:1,
fn:function(){
},
c:{
d:5
}
};
console.log(obj.hasOwnProperty("a"));//true
console.log(obj.hasOwnProperty("fn"));//true
console.log(obj.hasOwnProperty("c"));//true
console.log(obj.c.hasOwnProperty("d"));//true
console.log(obj.hasOwnProperty("d")); // false obj对象没有d属性
var str = new String();
console.log(str.hasOwnProperty('substring'));//false
console.log(String.prototype.hasOwnProperty('substring'));//true
//拓展:object1.isPrototypeOf(object2); isPrototypeOf是用来判断指定对象object1是否存在
//于另一个对象object2的原型链中,是则返回true,否则返回false。