为什么顶级函数作为JavaScript中的窗口方法创建? [英] Why top level functions are created as methods of window in JavaScript?
本文介绍了为什么顶级函数作为JavaScript中的窗口方法创建?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我们在Javascript中定义顶级命名函数时,它将成为窗口对象的一种方法。这个设计决策的原因是什么?
When we define a top level named function in Javascript, it becomes a method of the window object. What is the reason for this design decision?
推荐答案
Javascript总是运行在特定的全局上下文中。
在窗口对象的浏览器环境中,所以当你定义一个全局,你实际上将它添加到窗口...
Javascript always run in a particular global context. In a browser environment that is the window object, so when you define a global, you're actually adding it to window...
这是另一个很好的stackoverflow答案解释为什么这是这样的:
窗口是否真的在JavaScript中全球化?
Here is another excellent stackoverflow answer explaining why this is so: Is window really global in Javascript?
这篇关于为什么顶级函数作为JavaScript中的窗口方法创建?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文