var obj = {
MainFunction: function() {
AnotherSubFunction: function() {
}
var variable = AnotherSubFunction ()
}
}
- Can i do something like this...
- How can i call AnotherSubFunction using my obj? Is it possible.
- How to c开发者_StackOverflow中文版reate a function inside another function...
The code in your question is not valid Javascript. You're probably looking for:
MainFunction: function() {
function AnotherSubFunction() {
// ...
}
var variable = AnotherSubFunction();
}
Or maybe:
MainFunction: function() {
AnotherSubFunction = function() {
// ...
}
var variable = AnotherSubFunction();
}
However, in both cases, the name AnotherSubFunction
associated with the nested function only exists in the scope of the enclosing function (MainFunction
) and will not be accessible directly from obj
.
精彩评论