What does it mean, to write JavaScript in your own name scope, apparently it avoids conflicts and conforms to W3C standards but I have no idea what it means or how it is done?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
What I think you mean is namespacing. It means that you should contain your code in a namespace so that you won’t pollute the global scope (well, you did pollute it with only one variable and that’s about it). Every function and other stuff you intend to create will live in that namespace.
A simple namespace example, in object literal
You only declared one global,
ns. The rest are stored in it and accessible viansReal life examples can be seen in JS frameworks. For example, we have jQuery and Underscore
Although they have the same function names, but they live in separate namespaces. This avoids conflict, and helps you identify what belongs where.