您的位置:首页 > 其它

28. 原型

2015-09-04 16:42 447 查看
1. 原型



构造函数:

实例属性

实例方法

原型方法:

原型属性

原型方法

























function Box(){};
Box.prototype.name = 'Lee';
Box.prototype.age = 100;
Box.prototype.run = function(){
return "wjh";
};

var box = new Box();
alert(box instanceof Box);
alert(box instanceof Object);
alert(box.constructor == Box);  // true
alert(box.constructor == Object);  //false


字面量方式:
function Box(){};
Box.prototype.name = 'Lee';
Box.prototype.age = 100;
Box.prototype.run = function(){
return "wjh";
};
Box.prototype = {
name:'Lee',
age:100,
run:function(){ return "wjh";}
};

var box = new Box();
alert(box instanceof Box);
alert(box instanceof Object);
alert(box.constructor == Box);  // false
alert(box.constructor == Object);  //true


















寄生构造模式:



























内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: