javascript - Accessing another method inside the self-executing function -
let's assume define self-executing function following :
({ function1: function(){//...} function2: function(){//...} })
how can call function2 inside function1 ?
(i tried calling : function2(); , this.function2(); , none worked, both returned error : function2() or this.function2() not function)
actually part of aura framework, maybe specific framework.
there several things wrong here. first, not self-executing function. object 2 functions defined inside , wrapped in parentheses, make invalid. valid javascript object:
object1 = { function1: function(){ console.log('function1 called!'); // logs text 'function1 called!' console }, function2: function(){ console.log(this); // logs details of `object1` this.function1(); } }; object1.function2();
equivalent functionality using anonymous function this:
(function (){ console.log('anonymous function called!'); })();
note lack of curly brackets surrounding anonymous function. unlike functions in object, anonymous function isn't member of object. note last set of parentheses @ end, triggers execution of anonymous function has been defined.
javascript functions: https://developer.mozilla.org/en-us/docs/web/javascript/reference/functions
Comments
Post a Comment