Home >Web Front-end >JS Tutorial >Another implementation of JS namespace_javascript skills

Another implementation of JS namespace_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:25:551141browse

Copy code The code is as follows:

//, create a default, global namespace
var Company = {};
//Use objects to create sub-namespaces
Company.project = {};
//Create the final namespace, including some attributes whose values ​​are functions
Company.project.OA = {
add: function(a, b) { return a b; },
subtract: function(a, b) { return a - b; }
};

//Call
Company.project.OA.add(num1, num2);

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn