首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未定义的TypeError:在RefluxJS中,未定义的函数不是函数

未定义的TypeError:在RefluxJS中,未定义的函数不是函数
EN

Stack Overflow用户
提问于 2014-11-21 15:48:26
回答 1查看 273关注 0票数 0

以下是本网站的教程:http://blog.krawaller.se/posts/the-reflux-data-flow-model/

我正在考虑将var chatRef替换为虚拟数据,而不是使用new Firebase(...),如作者示例所示。搞不懂这行到底是怎么读的?

代码语言:javascript
复制
chatRef.on("value",this.updateChat.bind(this));

什么是“价值”以及bind是如何工作的?

尝试使用var chatRef = {0: "Hello", 1: "Hello"}产生Uncaught TypeError: undefined is not a function

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-21 16:28:56

chatRef似乎是具有至少一个自定义函数(push)的事件发射器。

你可以这样嘲笑它:

代码语言:javascript
复制
// you'll need to include an event emitter library
var chatRef = new EventEmitter(); 
chatRef.push = function(data, cb){
  // if push emits a value event?  not sure if it does
  this.emit('value', {val: function(){ return data });
  cb(null);
}

// emit a fake message every second
setInterval(function(){
  chatRef.push({text: "hey", from: "me", to: "them"}, function(){})
}, 1000);

如果你不明白,你应该读一读事件发射器。

.bind调用google Function.prototoype.bind。在本例中,绑定只是确保在调用回调时,它具有正确的this值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27065186

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档