我試圖訪問該我的箭函數內裏:這是不明確的箭頭功能
import myObject from '../myObjectPath';
export const myClass = Fluxxor.createStore({
initialize() {
this.list = [];
this.id = null;
},
myOutsideFunction(variable1) {
// here this in NOT undefined
myObject.getMyList(this.id, (myList) => {
// here this in undefined
this.list = myList;
}
});
)};
但箭頭函數內部它在馬回調函數,這是不確定的!
我使用通天transpile代碼:
myOutsideFunction: function myOutsideFunction() {
var _this = this;
myObject.getMyList(function (myList) {
_this.list = myList;
});
},
綁定'this',或將其存儲在箭頭函數範圍之外的臨時變量中。 – Jite
'this'的值取決於調用myOutsideFunction的方式。它怎麼叫? –
@Jit使用箭頭函數的全部想法是不必綁定這個! – Besat