Retrieving values from Execution Contexts in JavaScript

前端 未结 6 961
长发绾君心
长发绾君心 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:21

    No, it is absolutely impossible to access non-global shadowed variables in JavaScript.

    You cannot get the execution context of a function as well, it is an implementation-dependent internal value (specification type) - you are correct, your code was looking for properties on the function object.

    Variables in the global scope could be accessed as properties of the global object (window in browser), but if you are shadowing a local variable your only choice is to rename your own variable that casts the shadow.

提交回复
热议问题