I am bit confused with namespaces of function in javascript. Can I have function with same names?
Thanks
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.
There is no official concept of a namespace in Javascript like there is in C++. However, you can wrap functions in Javascript objects to emulate namespaces. For example, if you wanted to write a function in a “namespace” called
MyNamespace, you might do the following:Then, to call those functions, you would write
MyNamespace.myFunction(somearg, someotherarg);andMyNamespace.myOtherFunction();.I should also mention that there are many different ways to do namespacing and class-like things in Javascript. My method is just one of those many.
For more discussion, you might also want to take a look at this question.