Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/467.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript reactjs中的EventEmitter.prototype,this.on不起作用,并表示它';这不是一个函数_Javascript_Reactjs_Events_Eventemitter - Fatal编程技术网

Javascript reactjs中的EventEmitter.prototype,this.on不起作用,并表示它';这不是一个函数

Javascript reactjs中的EventEmitter.prototype,this.on不起作用,并表示它';这不是一个函数,javascript,reactjs,events,eventemitter,Javascript,Reactjs,Events,Eventemitter,及 正在处理我的addChangeListener和removeChangeListener。我已经导入了EventEmitter,并将其与对象分配一起使用(“对象分配”:“^4.1.1”) 但它会产生一个错误: bundle.js:41229未捕获类型错误:this.on不是函数 位于Object.addChangeListener(bundle.js:41229) 在Authors.componentWillMount(bundle.js:40504) 在callComponentWillM

正在处理我的
addChangeListener
removeChangeListener
。我已经导入了
EventEmitter
,并将其与对象分配一起使用(
“对象分配”:“^4.1.1”

但它会产生一个错误:

bundle.js:41229未捕获类型错误:this.on不是函数
位于Object.addChangeListener(bundle.js:41229)
在Authors.componentWillMount(bundle.js:40504)
在callComponentWillMount(bundle.js:26260)
在mountClassInstance(bundle.js:26356)
在updateClassComponent上(bundle.js:27725)
开始工作时(bundle.js:28366)
在执行工作时(bundle.js:31198)
在workLoop上(bundle.js:31227)
在htmlunknowneelement.callCallback(bundle.js:19504)
在Object.invokeGuardedCallbackDev(bundle.js:19542)

这是我的密码:

“严格使用”;
从“../dispatcher/AppDispatcher”导入AppDispatcher;
从“../constants/ActionTypes”导入ActionTypes;
从“事件”导入{EventEmitter};
从“对象分配”导入分配;
从“lodash”进口;
var CHANGE_事件=‘CHANGE’;
var_author=[];
var AuthorStore=assign({},EventEmitter.protoType{
addChangeListener(回调){
this.on(更改_事件,回调);
},
removeChangeListener(回调){
此.removeListener(更改事件,回调);
},
改变{
这个.发射;
},
getAllAuthors(){
返回作者;
},
getAuthorById(id){
返回u.find(_author{
id:id
});
}
});
AppDispatcher.register(函数(操作){
开关(action.actionType){
案例ActionTypes.INITIALIZE:
_author=action.initialData.authors;
AuthorStore.emitChange();
打破
案例ActionTypes.UPDATE\u作者:
var existingAuthor=u.find(_author{
id:action.author.id
});
var existingAuthorIndex=u.indexOf(_author,existingAuthor);
_author.splice(现有authorIndex,1,action.author);
AuthorStore.emitChange();
打破
案例操作类型。创建作者:
_author.push(action.author);
AuthorStore.emitChange();
打破
案例操作类型。删除作者:
_.删除(_author,函数(author){
return action.id==author.id;
});
AuthorStore.emitChange();
打破
违约:
}
});

导出默认作者库尝试console.log(this.on)并查看它是什么,以及它的availableit是否返回未定义的@Fatahn当你控制台时,这个
指的是什么
var AuthorStore=assign({},EventEmitter.protoType,{
{addChangeListener:ƒ,removeChangeStener:ƒ,emitChange:ƒ,getAllAuthors:ƒ,getAuthorById:ƒ}addChangeListener:ƒaddChangeListener(回调)emitChange:ƒemitChange()getAllAuthors:ƒgetAllAuthors()getAuthorById:ƒgetAuthorById(id)removeChangeListener:ƒremoveChangeListener(回调)uuu proto_uuu:Object
var AuthorStore=assign({},EventEmitter.protoType,{
返回错误后无法执行。
this.on('change', callback);
this.removeListener('change', callback);