通过互联网搜索我总是碰到这种Javascript类扩展的方法
function extend(Child, Parent) {
var F = function() { }
F.prototype = Parent.prototype
Child.prototype = new F()
Child.prototype.constructor = Child
Child.superclass = Parent.prototype
}
Run Code Online (Sandbox Code Playgroud)
但是这与那个有什么不同呢?
function extend(Child, Parent) {
var p = new Parent()
Child.prototype = p
Child.prototype.constructor = Child
Child.superclass = p
}
Run Code Online (Sandbox Code Playgroud)
最后一个也很完美.那我为什么要用这个额外的var F = function() { }动作呢?