1

I've found here is a good explication of the difference between run-time functions and parse-time ones. Bit what i'm trying to do is something like this

var funtionName = 'functionInside';
var start = function(){
    var a = function(){doSomething();}
    return {functionInside:a} 
};

And i want to call function 'functionInside' with the variable, something like

start.window[funtionName]()

Thanks in advance!

Community
  • 1
  • 1
Braian Mellor
  • 1,934
  • 3
  • 31
  • 50

1 Answers1

1

There are couple of ways to do that depending on what you need.

Here are two examples:

var start = {
  functionInside : function(){
    doSomething();    
  }
};

start[funtionName](); //different ways to invoke
start.functionInside();

Here's another approach:

var start = function() {
  this.functionInside = function() {doSomething();}
}

var s = new start();

s[funtionName](); //different ways to invoke
s.functionInside();
Benny Lin
  • 536
  • 3
  • 8