先看一下如下实例代码 function Person(name,age){ this.name=name; this.age=age; } Person.prototype.say=function(){ console.log("姓名:"+this.name+",年龄:"+this.age); } var p1=new Person("黎明",30); console.log(p1.name);//黎明 p1.say();//姓名:黎明,年龄:30 ...
先看一下如下实例代码 function Person(name,age){ this.name=name; this.age=age; } Person.prototype.say=function(){ console.log("姓名:"+this.name+",年龄:"+this.age); } var p1=new Person("黎明",30); console.log(p1.name);//黎明 p1.say();//姓名:黎明,年龄:30 ...