Retrieving values from Execution Contexts in JavaScript

前端 未结 6 1008
长发绾君心
长发绾君心 2021-01-27 15:40
var value = 10;

var outer_funct = function(){
    var value = 20;

    var inner_funct = function(){
        var value = 30;

        console.log(value); // logs 30
            


        
6条回答
  •  忘掉有多难
    2021-01-27 16:13

    Variables don't become properties of the functions under which you define them. Excluding the window object (in the case where they are globally declared) there's no object off of which you can access a locally-defined variable. There are workarounds as suggested by the other answers, but they are still a testament to JavaScript's inability to perform such a task in the actual circumstance that you've shown us.

提交回复
热议问题