In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
In this article, the editor introduces in detail "what are the differences between the node environment and the browser environment", the content is detailed, the steps are clear, and the details are handled properly. I hope that this article "what is the difference between the node environment and the browser environment" can help you solve your doubts.
Differences: 1, this points to global in node, while this points to window;2 in browser, js in browser mostly operates DOM directly or indirectly, but does not operate DOM;3 in node. Node provides more convenient components for reading and writing files, but not in browser.
Operating environment of this tutorial: windows10 system, nodejs version 12.19.0, Dell G3 computer.
What is the difference between the node environment and the browser environment
I. the direction of this in the global environment
This points to global in node and this to window in browsers, which is why a root is defined in underscore.
Var root = typeof self = 'object' & & self.self = self & & self | | typeof global = =' object' & & global.global = global & & global | | this
And there are a lot of API encapsulated under the window in the browser, such as alert, document, location, history and so on. We can't xxx (); or window.xxx (); in the node environment. Because these API are browser-level encapsulation, they are not stored in the javascript. Of course, node also provides a lot of node-specific API.
II. Js engine
Different browser vendors provide different browser kernels in browsers, and browsers rely on these kernels to interpret the js we write. But considering the small differences between different kernels, we need compatibility. Fortunately, there are some excellent libraries to help us deal with this problem, such as jquery, underscore, and so on.
Nodejs is based on Chrome's JavaScript runtime, that is, it actually encapsulates the GoogleV8 engine (for Google Chrome browsers). The V8 pilot engine executes Javascript very fast and the performance is very good.
NodeJS doesn't provide a simple wrapper and then an API call, and if that were the case, it wouldn't be as popular as it is now. Node optimizes some special use cases to provide an alternative API to make V8 run better in a non-browser environment. For example, in a server environment, dealing with binary data is usually necessary, but Javascript does not support it enough, so V8.Node adds the Buffer class to handle binary data conveniently and efficiently. Therefore, Node not only uses V8 simply, but also optimizes it to make it more powerful in all environments.
Js engines are fixed, but also corresponding to horse compatibility.
3. DOM operation
In most cases, js in browsers operates DOM directly or indirectly (some virtual DOM libraries and frameworks). Because the code in the browser mainly works in the presentation layer. But node is a server-side technology. There is no foreground page, so we will not operate DOM in node.
IV. Icano read and write
Unlike browsers, we need to read and write files like other server-side technologies, and nodejs provides more convenient components. It's a lot of trouble for browsers (to ensure compatibility) to open a local image directly in the page (don't tell me it's not easy, relative path. Try to know that either find a library or binary stream, or upload it with a network address displayed. Otherwise, why would someone want to build a js library), and all this node is done with one component.
5. Module loading
A feature of javascript is that the native API that does not provide package references executes all the things to be loaded at once, so it depends on the power of your closures. The things used are all together, there is no divide and rule, and it is particularly illogical and reusable. If the page is simple or the site is, of course, we can do it through some AMD and CMD js libraries (such as requireJS and seaJS). In fact, many large websites do this.
The API loaded by CMD's module is provided in nodeJS. If you have used seaJS, you should get started quickly.
Node also provides npm as a package management tool, which can manage the libraries we drink more effectively and conveniently.
Of course, ES6 on the browser side also has this supplement, and I believe it will be better in the future.
After reading this, the article "what is the difference between node environment and browser environment" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.