【发布时间】:2018-02-15 11:57:06
【问题描述】:
我已经创建了一个对象和一个 mixin,我已经将 mixin 分配给了 Object,但是我似乎无法从 mixin 访问该对象?
mixin.js
module.exports = {
doSomething: () => {
let something = this.something.title;
}
};
object.js
class Thing {
constructor(something) {
this.something = something;
}
_otherFunction() {
// does stuff
}
}
module.exports = Thing;
index.js
const Something = require('./mixin');
const Thing = require('./Object');
Object.assign(Thing.prototype, Something);
当我实例化 Thing 并调用 doSomething() 时,它就无法访问 this.something...所以
let thing = new Thing({title: 'abc'});
thing.doSomething();
我收到错误无法读取未定义的属性“标题”
【问题讨论】:
标签: javascript node.js mixins