开发者

How can i call AnotherSubFunction using my obj

开发者 https://www.devze.com 2023-03-20 20:51 出处:网络
var obj = { MainFunction: function() { AnotherSubFunction: function() { } var variable = AnotherSubFunction ()
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.

0

精彩评论

暂无评论...
验证码 换一张
取 消