If I have:
var myFunction = function() {
var myInner = function() {
}
}
then how do I call myFunction.myInner()?
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.
Functions are scopes in JavaScript. You cannot call a function from within a function, unless, you declare it as a method. Some have suggested that you use objects or weird patterns, which may or may not be what you want…
If you want a “class-like” function with public/private methods and variables, do this:
JavaScript does not have actual classes, but it is easiest to describe this pattern as “class-like”.
Obviously, you can add as many public/private methods, objects, etc. as you like.
Also note, DO NOT FORGET THE “new” OPERATOR WHEN CREATING AN INSTANCE WITH THIS PATTERN…if you do, then “this” is bound to your global space and can override other application data (name collisions).
Hope this helps, good luck!