如何在javascript对象文字中引用其他内容?

时间:2015-01-26 22:57:56

标签: javascript reactjs

如何在javascript对象文字中引用其他内容?例如:

var Dispatcher = require('../dispatchers/dispatcher.js');

var App = React.createClass({

    handleEvent : function(item){
        //...
    },

    events : {
        dispatcherIndex: Dispatcher.register(function(payload) { //register a callback and set the result
           this.handleEvent(payload); //this 'this' is the wrong one since this is being called as a callback
           //how do i reference the right one (the one that has the handleEvent function)?
        })
    }
});

如您所见,我们注册了一个回调。因此,该回调中的'this'引用不会引用我们想要的对象。当我们不能为'this'创建一个闭包时,我们该怎么做?

0 个答案:

没有答案