1.对象的原始模式:
var b={ barcode:'aaa',count:1};
2.对象的构造函数模型:
例子1:
function School1(name, sex){//原型对象也就相当于一个类; this.name = name; this.sex = sex; } School1.prototype.play=function(){//这就是原型的方法 console.log(this.name); }
例子2:
function School2(name, sex){ this.name = name; this.sex = sex; this.play = function(){ return console.log(this.name);//这是对象方法; } }
对于构造函数的实例化必须加new:
var k=new School1('王色', '男'); var h=new School2('小花','女'); k.play();>>王色; h.play();>>小花;