简体   繁体   English

带字符串的函数运行时内部的JS Call函数

[英]JS Call function inside function run-time with string

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 我想用变量调用函数“ functionInside”,就像

start.window[funtionName]()

Thanks in advance! 提前致谢!

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM