当我们使用 javascript 继承,并且子类从其父类继承时,我们总是这样做:
var klass = function(){ this.init.apply(this, arguments)};
if(parent) {
var subclass = function(){};
subclass.prototype = parent.prototype;
klass.prototype = new subclass;
}
上面的代码来自《Javascript Web Application》,我很困惑它和下面有什么区别:
var klass = function(){ this.init.apply(this, arguments)};
if(parent) {
klass.prototype = parent.prototype;
}
谁能给我解释一下?