函数表达式是否假设词法封闭函数上下文?

时间:2018-03-05 10:38:20

标签: javascript arrow-functions function-expression

我对function declarations does not has lexical contextarrow function it does have充满信心,但如果function expression does我感到困惑?

根据我所读到的它没有,但在following example中它可以正常工作(使用函数表达式和箭头函数),因此在我看来has lexical context。理解arrow function后,它只是short syntax of the function expression所以它有same capacities。我错了吗?

请参阅未注释的代码:

// Delete users for ADMIN with GET 
        document.addEventListener("click", function (e) {

            if (e.target.classList.contains("btnDeleteUser")) {
                /// get users based on id
                sUserId = e.target.getAttribute("data-userId");
                //console.log(sUserId);
                /*getAjax("api_delete_user.php?id=" + sUserId, function(ajUserDataFromServer) {
                deleteUser(e, ajUserDataFromServer);*/
                /*getAjax("api_delete_user.php?id=" + sUserId, (ajUserDataFromServer) => {
                    deleteUser(e, ajUserDataFromServer); 
                    })*/
                getAjax("api_delete_user.php?id=" + sUserId, deleteUser.bind(this, e));

            }
        });

0 个答案:

没有答案