In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to understand namespaces in Js". The content of the explanation is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to understand namespaces in Js".
Before the introduction of namespaces, a headache for developers was how to prevent conflicts between function names / class names and others. This problem can be solved by naming prefixes (such as prefixes, etc.) between a company's internal project team. however, focusing on the whole field of software development, in today's era of collaborative development, this problem still exists.
Why use namespaces
When using multiple third-party frameworks or libraries, the only thing you can do is to pray that their names don't conflict, and if such a disaster happens, the only thing you can do is to give up one of them. The introduction of namespaces solves this problem to a considerable extent, of course, if you use the same namespace as other companies unfortunately, and the other side is Microsoft, SUN and other bigwigs, congratulations, hehe @ _ @!
Namespaces in Javascript
When you are engaged in Web development, you will inevitably come into contact with JavaScript, and the latest version of JavaScript still does not support namespaces, so the problem of naming conflicts is obvious. Imagine referencing two js files, only to find that you have to give up one of them due to naming problems, resulting in writing a lot of code, which is undoubtedly very frustrating. Before the concept of namespace was introduced in the new version of JavaScript, it was the basic obligation of us programmers to carry forward the spirit of self-reliance and creativity.
Implementation premise: unlike Delphi, C # and other languages, the class in JavaScript is not the definition of an object. In fact, there is no real class in JavaScript. The class here is actually implemented by function simulation, while the function in JavaScript is actually an object, so in JavaScript: a class is an object. This is very different from traditional conceptual concepts, where in JavaScript, creating an instance of a class is actually a copy of the class (= object, remember). As you can see here, anyone with a design pattern concept should be able to see that in JavaScript, the class mechanism uses the prototype pattern.
Realization method
Implementation principle: now that we see the nature of the class clearly, then the problem is simple. If you put all the JS classes and functions of the GEA project group as attributes in the object named GEA, and then put the GEA object in a property called Grandsoft object, you can achieve our goal. For example, Grandsoft.GEA.Person is actually a class Person (or an object) in the property GEA (also an object) of the Grandsoft object.
Thank you for your reading, the above is the content of "how to understand namespaces in Js". After the study of this article, I believe you have a deeper understanding of how to understand namespaces in Js, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.