The following is the code
function A(){
this.a = 1;
this.b = 2;
}
A.prototype.drive = function(){
console.log('drivvvvvvvvvv');
}
//方式1
function B(){}
B.prototype = Object.create(new A()); //这里采用了new 一个实例
//方式2
function C(){
A.call(this);
}
C.prototype = Object.create(A.prototype) //这里使用的是父类的原型
What is the difference between the above two methods? Why do I think mdn uses the second one?
过去多啦不再A梦2017-05-19 10:17:44
1 Disadvantages:
Executing new is equivalent to running A once. If you do some other things in A (such as changing global variables), there will be side effects.
Use the object created by A as a prototype, which may have some redundant attributes.
2 simulates the execution process of new