以下是本网站的教程:http://blog.krawaller.se/posts/the-reflux-data-flow-model/
我正在考虑将var chatRef替换为虚拟数据,而不是使用new Firebase(...),如作者示例所示。搞不懂这行到底是怎么读的?
chatRef.on("value",this.updateChat.bind(this));什么是“价值”以及bind是如何工作的?
尝试使用var chatRef = {0: "Hello", 1: "Hello"}产生Uncaught TypeError: undefined is not a function
发布于 2014-11-21 16:28:56
chatRef似乎是具有至少一个自定义函数(push)的事件发射器。
你可以这样嘲笑它:
// 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值。
https://stackoverflow.com/questions/27065186
复制相似问题