标签:
function Student(name,age){ this.name=name; this.age=age; } var student = new Student(‘yjj‘,15); alert(Student.prototype.isPrototypeOf(student));//true
function Student(name,age){ this.name=name; this.age=age; } var student = new Student(‘yjj‘,15); alert(Object.getPrototypeOf(student )==Student.prototype);//true
此方法为ECMAScript 5新增,支持该方法的浏览器有IE9+,Firefox 3.5+,Safari 5+,Opera 12+,Chrome.
function Student(name,age){ this.name=name; this.age=age; } Student.prototype.xxx=‘ssss‘;
var student = new Student(‘yjj‘,15); alert(student.hasOwnProperty(‘name‘));//true alert(student.hasOwnProperty(‘xxx‘));//false
function Student(name,age){ this.name=name; this.age=age; } Student.prototype.xxx=‘ssss‘; var student = new Student(‘yjj‘,15); alert("name" in student); //true alert("xxx" in student); //true
判断一个对象的属性是否是原型属性。
function hasPrototypeProperty(object,name){ return !object.hasOwnProperty(name)&&(name in object) //不是自身属性,但能够访问到 就是原型属性 }
标签:
原文地址:http://www.cnblogs.com/yangjingqi/p/4337514.html