我试图使用Lo-Dash javascript库在javascript中模拟继承.
我只是使用_.extend这样做:
function Parent() {
var self = this;
self.hello = function () {
console.log('Hello from parent');
};
}
function Child() {
var self = this;
_.extend(self, Parent);
}
Child.hello(); // Doesn't exist
Run Code Online (Sandbox Code Playgroud)
我认为这可行,因为所有的javascript函数都是对象,但显然我错了.为什么这不起作用,我将如何使用Lo-Dash正确模拟继承?