1、应用方法
hasOwnProperty
2、应用实例
class Student{
constructor(sno,sname,sage,ssex) {
this.sno = sno;
this.sname = sname;
this.sage = sage;
this.ssex = ssex;
}
toString(){
return '学号:' + this.sno + ',姓名:' + this.sname + ',年龄:' + this.sage + ',性别:' + this.ssex;
}
}
let s = new Student('1','张思',20,'女');
let info = s.toString();
console.log(info);
let name = s.hasOwnProperty('sname');
let age = s.hasOwnProperty('age');
let sex = s.hasOwnProperty('sex');
console.log(name,age,sex);
let to = s.hasOwnProperty('toString');
console.log(to);
let tos = s.__proto__.hasOwnProperty('toString');
console.log(tos);
3、运行结果
学号:1,姓名:张思,年龄:20,性别:女
true false false
false
true