原型创建对象

//原型创建对象
function Box(){};

Box.prototype.name = 'Lee';
Box.prototype.age = 100;
Box.prototype.run = function(){
    return this.name + this.age + 'running....';
};

var box1 = new Box();
var box2 = new Box();
// alert(box1.run());

//如果是实例方法,不同的实例化,他们的方法地址是不一样的,是唯一的
//如果是原型方法,那么他们的地址是共享的,都是一样的
alert(box1.run == box2.run);

 

posted @ 2014-08-17 15:11  little fly  阅读(176)  评论(0编辑  收藏  举报