2016-04-22 2 views
0

Ich habe folgende verschachtelte Funktion wie folgt aus:Wie targeted geschachtelte Ausdruck/Funktion jquery?

var initApp = (function(app) { 

app.testOne = function() { 

    if (conditions === true) { 
     testTwo(); 
    } 
    console.log("test 1 fired"); 

    var testTwo = function() { 
     console.log("test 2"); 
    } 
} 
return app; })({}); 

ich verwenden kann „initApp.testOne()“ testone nennen, aber wie rufe ich testTwo()?

Antwort

2

Sie versuchen testTwo aufrufen, bevor sie deklariert ist:

var initApp = (function (app) { 

    app.testOne = function() { 

     var testTwo = function() { 
      console.log("test 2"); 
     } 
     if (conditions === true) { 
      testTwo(); 
     } 
     console.log("test 1 fired"); 

    } 
    return app; 
})({}); 
+0

, wie richte ich das von der Wurzel? z. B. initApp.testOne.testTwo(); – user1467439

+0

gah das war so offensichtlich! : Ich brauche etwas Schlaf !!! – user1467439