【发布时间】:2015-11-16 06:25:48
【问题描述】:
class Foo extends EventEmitter {
constructor(name) {
this.name = name;
}
funcA(sourceRepositoryPath, branch) {
this.emit('log', 'Hello from Foo');
var bar = new Bar();
bar.on('log', function(log) {
this.emits('log', 'Hello from Foo from Bar');
});
}
}
如何在 bar.on... 函数中使用来自 Foo 的 emit 函数,如
this.emit('log', 'Hello from Foo');
ES6 中的函数?
var foo = new Foo();
foo.funcA();
foo.on('log', function(log) {
// expects : Hello from Foo && Hello from Foo from Bar
// gets : Hello From Foo
});
【问题讨论】:
-
为什么人们总是写“EC6”?该术语在任何地方都使用过吗?
-
我只是简写了Ecmacript 6,不知道是否常用。
-
好的,谢谢你提到这一点,我以后会使用正确的缩写:)
标签: javascript node.js class ecmascript-6 eventemitter