In backbone.js under the inherits method, the authors does this:
var ctor = function() {};
// some other code ...
var child;
// some other code ...
ctor.prototype = parent.prototype;
child.prototype = new ctor();
The above as I understand it is to allow the new object to inherit the prototypical chain of the parent. I'm trying to wrap my head around this, but in practice, is there a difference between the above and assigning the prototype directly?
child.prototype = parent.prototype
I understand that there exists this [[prototype]] object that cannot be accessed directly unless through the new keyword. However, given that most object declarations are of the form
var SomeObj = function() {};
SomeObj.prototype.test = function() { return "Hello World"; }
What would be the practical differences in the above prototype assignments?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…