二、Object对象
经典属性和方法
1、constructor
对象的构造函数
2、hasOwnProperty(propname)
3、isPrototypeOf(o)
4、toString()
5、valueOf()//获取一个对象的原始值
var bool = new Boolean(0);
document.write(bool.valueOf());//false
举例:
function person(name, age) {
var sex = “boy”;
this.name = name;
this.age = age;
this.method1 = function(){
return name+age;
}
}
var p = new person(“kobe”, 21);
console.log(p.isPrototypeOf(Object));//false
console.log(p.hasOwnProperty(“name”));//true
console.log(p.method1());//kobe21
console.log(p.constructor);//原函数
console.log(p.name);//kobe
console.log(p.sex);//undefined注意,sex是私有属性,只有在方面里面可以调用