内存和一些有关 JavaScript 的更多信息

发布于 2024-11-19 12:55:02 字数 259 浏览 6 评论 0原文

  1. JavaScript 中的内存是如何工作的?有栈吗?一堆?内存管理如何工作?

  2. 变量和它在内存中的位置之间的绑定何时发生?在运行时之前或期间?

  3. JavaScript 中有模块或类似的东西吗? JavaScript

  4. 另外,你认为 JS 是可移植的吗?并且可靠?请对你的答案进行简短的解释。

我在互联网上寻找答案,但似乎没有找到。快速回答也将受到赞赏。

  1. How does the memory work in JavaScript? Is there a stack? A heap? How does memory management work?

  2. When does the binding between the varriable and its place in memory occurs? Before or during runtime?

  3. Is there modules or anything similar in JavaScript?

  4. Also, would you say JS is portable? And reliable? Please give a short explanation to your answer.

I was searching for answers on the internet, but I don't seem to find any. Quick answers are appreciated as well.

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

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

发布评论

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

评论(2

故笙诉离歌 2024-11-26 12:55:02

内存是在 javascript 中为您管理的,因此您实际上不必担心它,除了确保您不会使用大量的内存之外。当对象不再有引用或者超出范围时,垃圾收集器将释放该对象。它的幕后工作方式实际上取决于实现,而不是由语言定义的。

即使函数框架(例如局部变量)也以这种方式工作(而不是传统的面向堆栈的方式),它允许 JavaScript“闭包”,这些函数框架在没有嵌入函数再引用它们之前不会被释放。

Javascript 代码本身是完全独立于机器的,因此它非常可移植。实际上,应用程序的可移植性通常更多地取决于 JavaScript 与之交互的库(例如浏览器 DOM),而不是语言。它由一系列 ECMA 规范记录,并且该规范有不同的版本号,随着语言的发展定义了各种新功能。

我认为 javascript 非常可靠,只要您不尝试使用最近引入的在不同实现中不可用的功能,就很少有真正的 javascript 问题。有大量的跨浏览器兼容性问题,但这些问题几乎都不是语言本身,而是浏览器 DOM 或语言与 DOM 之间的交互。

我不确定你所说的“模块”是什么意思。

Javascript 是一种解释性语言,因此变量与其在内存中的位置之间没有固定的绑定。所有变量都通过其名称进行引用,并且由实现来确定如何最好地解析名称与存储值的特定内存块之间的连接。

Memory is managed for you in javascript so you don't really have to worry about it other than making sure you don't use ridiculous amounts of it. When there are no references left to an object or it has gone out of scope, it will be freed by a garbage collector. How it works under the covers is really implementation dependent and not defined by the language.

Even function frames (e.g. local variables) work this way (and not the traditional stack oriented way) which allows for javascript "closures" which are function frames that are not released until no embedded functions have references to them any more.

Javascript code itself is completely machine independent so it's very portable. In practice, the portability of an application typically depends upon the libraries that javascript interacts with (e.g. browser DOM) more so than the language. It's documented by a series of ECMA specifications and there are different version numbers of that specification which define various new features as the language has evolved.

I consider javascript very reliable and, as long as you don't try to use recently introduced features that aren't available in different implementations, there are rarely true javascript issues. There are tons of cross-browser compatibility issues, but those are nearly all NOT in the language itself, but in the browser DOM or the interaction between the language and the DOM.

I'm not sure what you mean by "moduls".

Javascript is an interpreted language so there is no fixed binding between a variable and it's place in memory. All variables are referenced by their name and it's up to the implementation to determine how to best resolve the connection between a name and a specific piece of memory that stores the value.

屋顶上的小猫咪 2024-11-26 12:55:02

A. 只有堆。 Javascript 使用自动垃圾收集。我可以假设您有 C/C++ 经验吗?在 JS 中,成功的秘诀几乎就是:“只要忘记内存管理,你就会没事的”。

B. 绑定发生在运行时。请记住,Javascript 不是编译语言,因此没有编译时,只有运行时。

C. 与所有 C 风格语言一样,Javascript 使用 % 作为模运算符,快速谷歌搜索就会发现。

D. 它非常便携,因为它在浏览器上运行,而不是直接在系统上运行。几乎任何运行 Firefox 或 Chrome 的系统都将运行 Javascript,这意味着 MS Windows、Linux、Mac、BSD,以及任何现代系统。

D'。 Javascript 有多种实现方式。问“Javascript可靠吗?”就像问:“汽车可靠吗?”。有许多不同的汽车,或多或少都可靠; JavaScript 也一样。

A. There is only the heap. Javascript uses automatic garbage-collection. May I assume you have experience with C / C++? In JS, the recipe for success is pretty much: "Just forget all about memory management and you'll be fine".

B. The binding occurs at runtime. Remeber that Javascript is not a compiled language, so there is no compile-time, only runtime.

C. Like all c-style languages, Javascript uses % as a modulus operator, as a quick google search would have revealed.

D. It's very portable, since it runs on the browser, not directly on the system. Pretty much any system that runs Firefox or Chrome will run Javascript, meaning MS Windows, Linux, Mac, the BSDs, any modern system really.

D'. There are several implementations of Javascript. Asking "Is Javascript reliable?" is like asking: "Are cars reliable?". There are many different cars, which are more or less reliable; same for Javascript.

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