面像对象略整理
function Person(name, age, job){
this.name = name;
this.age = age;
this.job = job;
this.sayName = function(name){
alert(this.name);
};
}
var person1 = new Person("Nicholas", 29, "Software Engineer");
var person2 = new Person("Greg", 27, "Doctor");
console.log(person1.sayName==person2.sayName)//fasle
console.log(person1.sayName()==person2.sayName())//true
function Perple(){};
Perple.prototype.name="hong";
Perple.prototype.age=18;
Perple.prototype.height="188cm"
Perple.prototype.sayName=function(){
alert(this.name)
};
var p3=new Perple();
var p4=new Perple();
alert(p3.sayName==p4.sayName);//true
console.log(Perple.prototype.isPrototypeOf(p3));//true;isPrototypeOf()检测一个原型上是不是有这个实例
console.log(p3.hasOwnProperty("name"))//fasle检测一个属性是不是存在实例中
p4.name="圆圆";
alert(hasPrototypeProperty(p3, "name"))
console.log(p4.hasOwnProperty("name"));//true
console.log("name" in p4)//true检测该属性是否存在实例 || 原型中(二选一符合就返回true)
var obj={name:"hong",age:"45"};
for(var oo in obj){//for in 的用法
console.log("属性值:"+obj[oo]+" 属性名:"+oo);
}