您的位置:首页 > 其它

继承的4种基本方式

2016-03-06 16:19 399 查看
1、构造继承

function Parent(){
this.name = "Parent";
}
function Child(){
Parent.call(this);
}
var child = new Child();
console.log(child.name);


2、原型继承

function Parent(){
this.name = "Parent";
}
function Child(){
}
Child.prototype = new Parent();
var child = new Child();
console.log(child.name);


3、实例继承

function ArrayCollection(){
return [];
}

var ac = new ArrayCollection();


比较奇特的继承,跟直接执行函数一样,得到的是返回值。

4、拷贝继承
拷贝继承,满大街都是,分深层拷贝和浅层拷贝两种。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: