本文介绍了为什么Node.js没有原生DOM?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我发现 Node.js是使用V8 JavaScript引擎构建时,我想:




  1. 为什么当它使用与Chrome相同的JavaScript引擎时,它没有原生DOM?

  2. 为什么它没有在检索到的页面中运行JavaScript的模式?

  3. 我不了解JavaScript引擎与Web浏览器中的引擎有什么关系?

非常感谢!

推荐答案

DOM是DOM,JavaScript实现只是一个单独的实体。 DOM表示Web浏览器向JavaScript环境公开的一组工具。然而,没有要求任何特定的JavaScript运行时都会有通过全局对象公开的任何设施。

The DOM is the DOM, and the JavaScript implementation is simply a separate entity. The DOM represents a set of facilities that a web browser exposes to the JavaScript environment. There's no requirement however that any particular JavaScript runtime will have any facilities exposed via the global object.

什么节点.js是一个独立的JavaScript环境完全独立于Web浏览器。 Web浏览器和JavaScript之间没有内在联系; DOM是不是 JavaScript语言或规范的一部分或任何东西。

What Node.js is is a stand-alone JavaScript environment completely independent of a web browser. There's no intrinsic link between web browsers and JavaScript; the DOM is not part of the JavaScript language or specification or anything.

我在Java中使用旧的基于Rhino Java的JavaScript实现 - 基于Web服务器。该环境与任何DOM都没有任何关系。这是我自己的应用程序负责用设施填充全局对象来做我需要它做的事情,而且它不是DOM。

I use the old Rhino Java-based JavaScript implementation in my Java-based web server. That environment also has nothing at all to do with any DOM. It's my own application that's responsible for populating the global object with facilities to do what I need it to be able to do, and it's not a DOM.

注意有如果你想在Node项目中使用虚拟DOM,那么像这样的项目。由于DOM本身就是服务器端平台,因此DOM是Node无法使用的工具,并且对于各种服务器应用程序仍然具有完美的意义。这并不是说DOM可能对某些人没用,但它与流程控制,I / O,网络,数据库互操作等等的服务类别不同。

Note that there are projects like jsdom if you want a virtual DOM in your Node project. Because of its very nature as a server-side platform, a DOM is a facility that Node can do without and still make perfect sense for a wide variety of server applications. That's not to say that a DOM might not be useful to some people, but it's just not in the same category of services as things like process control, I/O, networking, database interop, and so on.

对于为什么?这个问题,可能会有一些官方回答。在那里,但它基本上只是维护Node(现在的Node Foundation)的人的业务。如果某些勇敢的开发人员在那里决定Node应该默认发布一组模块以支持虚拟DOM,并且成功地工作并且可以实现,那么Node 拥有一个DOM。

There may be some "official" answer to the question "why?" out there, but it's basically just the business of those who maintain Node (the Node Foundation now). If some intrepid developer out there decides that Node should ship by default with a set of modules to support a virtual DOM, and successfully works and works and makes that happen, then Node will have a DOM.

这篇关于为什么Node.js没有原生DOM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 08:55