标签:而且 一句话 2-2 func 链接 test ima 解决方法 phi
var person1={
name:"memphis",
age:26,
showMessage:function(){
alert("name:"+this.name);
}
};
person1.showMessage();//输出name:memphis
var person2={
name:"memphis",
age:26,
showMessage:function(){
alert("name:"+this.name);
}
};
function Person(name,age)={
this.name=name;
this.age=age;
this.showMessage=function(){
alert("name:"+this.name);
};
}
var person1=new Person(tan,26);
var person2=new Person(song,16);
function Person(){} //Person构造函数
var p=new Person(); //Person构造函数创建对象,也可叫做实例化
function Person(name,age)={ this.name=name; this.age=age; this.showMessage=showMessage; } function showMessage(){ alert("name:"+name); }
//建房子 function Person(){ } //房子里有什么并确定了指针的指向 Person.prototype={ name:"memphis", age:"22", showMessage:function(){ alert("name:"+this.name); } }; var person1 = new Person();
例如: function Person(name,age){ this.pname=name; this.page=age; } Person.prototype={ showPMessage:function(){ alert("name:"+this.pname); } }; function Man(name,age){ this.mname=name; this.mage=age; } // 这一句话表示原型的指针指向了Person Man.prototype = new Person("memphis",22,"man"); // 给原型添加方法一定要放在替换原型的语句之后 Man.prototype.test="wo shi"; Man.prototype.showMMessage=function(){ alert("name:"+this.mname); }; var song=new Man("song",1); song.showMMessage();//显示song song.showPMessage();//显示memphis
function Person(){ //父类 this.name="水煮鱼"; this.age=18; } function Son(){ //子类 } var p=new Person(); var s=new Son(); for(var k in p){ s[k]=p[k]; } console.log(s.name); //水煮鱼 console.log(s.age); //18
function Human(){
this.name="香辣虾";
this.age=21;
}
function Man(){
}
Man.prototype=new Human();
var m=new Man();
console.log(m.name); //香辣虾
console.log(m.age); //21
var animal={ name:"阿咪", type:"猫科" }; var a=Object.create(animal) //ES5属性 console.log(a.name); //阿咪 console.log(a.type); //猫科
标签:而且 一句话 2-2 func 链接 test ima 解决方法 phi
原文地址:http://www.cnblogs.com/memphis-f/p/7350882.html