相关疑难解决方法(0)

这在箭头函数中是未定义的

我想在我的箭头函数中访问它:

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;
        } 
    });
)};
Run Code Online (Sandbox Code Playgroud)

但是内部的箭头功能在ma回调函数中这是未定义的!!

我正在使用babel来传输代码:

myOutsideFunction: function myOutsideFunction() {
    var _this = this;
    myObject.getMyList(function (myList) {
        _this.list = myList;
    });
},
Run Code Online (Sandbox Code Playgroud)

javascript this undefined arrow-functions

6
推荐指数
1
解决办法
4625
查看次数

标签 统计

arrow-functions ×1

javascript ×1

this ×1

undefined ×1