因此,下面是一個非常簡單的例子,我將that
設置爲this
,因此我可以使用myObj
的範圍。我將如何整合Function.prototype.bind,以便我可以看到未來如何使用它?將JavaScript的.bind()與回調函數集成在一起
var myObj = {
specialFunction: function() {
},
anotherSpecialFunction(){
},
getAsyncData: function (cb) {
// an operation
cb();
},
render: function() {
var that = this;
this.getAsyncData(function() {
that.specialFunction();
that.anotherSpecialFunction();
});
}
};
myObj.render();
''''會給你''render'函數的範圍,而不是'myObj' – Vandesh
@Vandesh我不認爲你就在那裏...... – benhowdle89
getAsyncData'定義在哪裏?它假設是myObj.getAsyncData? – Musa