标签:
由于JS是解释执行的语言,那么代码中出现函数与对象如果重复执行,会创建多个副本
function Person(name,age,gender){
this.name=name;
this.age=age;
this.gender=gender;
this.sayHello=function(){};
}
function sayHello(){};
function Person(name,age,gender){
this.name=name;
this.age=age;
this.gender=gender;
this.sayHello=sayHello;
}
function Person(name,age,gender){
this.name=name;
this.age=age;
this.gender=gender;
}
Person.prototype.sayHello=function(){
console.log( ‘hello!‘ ) ;
};
var p1=new Person(‘张三‘,10,‘male‘);
p1.sayHello()
var p2=new Person(‘张四‘,13,‘male‘);
p2.sayHello();
关于面向对象的概念
原型相关的概念
如何使用原型
Student.prototype = {
sayHello: function () {},
study: function () {}
};
标签:
原文地址:http://www.cnblogs.com/ghlucky/p/5724097.html