gpt4 book ai didi

javascript - 这是否使用作用域链?

转载 作者:行者123 更新时间:2023-11-30 07:22:39 26 4
gpt4 key购买 nike

var a = 1;

function hello() {
(function(){
alert(a);
}());
}

或者仅当使用 prototype 属性将对象链接在一起时才使用作用域链?

最佳答案

是的,使用了作用域链。作用域链与闭包更相关。

当调用 hello 时,为了获取 alert(a)a 的值,在内部匿名函数中搜索变量 a

没有找到任何东西,它向上移动到函数 hello,然后向上移动到定义 hello 的函数/全局范围。

关于javascript - 这是否使用作用域链?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32461593/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com