How to use functions to create namespaces in JavaScript
This article will explain in detail how to use functions to create namespaces in JavaScript. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Create through function (function): (more complex)
This is a common way to write, by declaring a function implementation, setting initial variables in the function, and writing public methods to prototype, such as:
Var NameSpace = NameSpace | | {}; / * Function * / NameSpace.Hello = function () {this.name = 'world';}; NameSpace.Hello.prototype.sayHello = function (_ name) {return' Hello'+ (_ name | | this.name);}; var hello = new NameSpace.Hello (); hello.sayHello () This is the end of the article on "how to use functions to create namespaces in JavaScript". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.