我有一個基類延伸時不派生類可用的:使用Javascript - 基類方法使用lodAsh
class Base {
constructor() {
this.name = "base_class"
}
getBaseName() {
return "base"
}
}
和派生類
var _ = require('lodash');
class Derived {
constructor() {
this.name = "derived"
}
getDerivedName() {
return "derived"
}
}
_.extend(Derived.prototype, Base)
我期待具有在getBaseName
可用派生類。但事實並非如此。我該怎麼做?我錯過了什麼?
var derived = new Derived();
console.log(derived.getBaseName)
-- undefined
不應該是'_.extend(Derived.prototype,Base.prototype)'? –