javascript 中对象的作用域与其上下文有什么区别?

发布于 2024-08-29 20:16:15 字数 889 浏览 4 评论 0原文

用白话来说,范围上下文有很多共同点。这就是为什么当我阅读对两者的引用时,我感到困惑,例如下面关于闭包的文章的引用:

范围是指变量和函数可以访问的位置,以及它在什么上下文中执行。 (@robertnyman)

据我所知告诉你,上下文只是对对象的引用。

有人可以解释一下context到底是什么吗,例如在jQuery语法中使用的$(selector, context)。对象的范围与其上下文相同吗?


更新:

我发现这篇有趣的文章讨论了 JavaScript 中的范围和上下文。

http://www.digital-web.com/articles/scope_in_javascript/

In the vernacular, scope and context have a lot in common. Which is why I get confused when I read references to both, such as in the quote below from an article on closures:

Scope refers to where variables and functions are accessible, and in what context it is being executed. (@robertnyman)

As far as I can tell, context is just a reference to an object.

Can someone please explain what exactly is context, as used, for instance, in the jQuery syntax, $(selector, context). And is an object's scope the same at it's context?


Update:

I found this interesting article that talks about both scope and context in JavaScript.

http://www.digital-web.com/articles/scope_in_javascript/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

烧了回忆取暖 2024-09-05 20:16:15

此 jQuery 示例中使用的“Context”不是 JavaScript 术语。它只是一个变量的名称。它与 jQuery 文档的其余部分一起记录: http://api.jquery.com/jQuery /#选择器上下文

"Context", as used in this jQuery example, is not a JavaScript term. It is just the name of a variable. It is documented with the rest of the jQuery documentation: http://api.jquery.com/jQuery/#selector-context

回心转意 2024-09-05 20:16:15

“上下文”可以意味着很多东西。在您引用的 jQuery 示例中,它是对应该应用选择器的 DOM 部分的引用,这与 JavaScript 上下文无关。

"context" can mean many things. In the jQuery example you quote it is a reference to a part of the DOM that the selector should be applied to, which has nothing to do with JavaScript contexts.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文