몇 주 전에 같은 질문을했지만 나는 약간 다른 표현을했다고 생각합니다. this.
기본적으로 한 번에 functionname
문자열을 구문 분석해야합니다.
그런데 그 대답의 코드 walk_path
을 사용하여, 여기에 인수를 포함한 문자열에서 함수를 실행하기 위해 작성한 일반적인 목적 함수가 있습니다.
// run an arbitrary function from a string. Will attempt to parse the args from parenthesis, if none found, will
// use additional arguments passed to this function.
utils.runFunction = function (funcdef) {
var argPos = funcdef.indexOf('(');
var endArgPos = -1;
var args = undefined;
var func = funcdef;
if (argPos > 0) {
endArgPos = funcdef.indexOf(')', argPos);
if (endArgPos > 0) {
args = funcdef.substring(argPos + 1, endArgPos).split(',');
func = funcdef.substring(0, argPos - 1);
}
} else {
args = Array.prototype.slice.call(arguments, 1);
}
var func = walk_path(window, func);
return !args ? func() : func.apply(null, args);
};
'functionname === init' 또는'functionname === 'init''입니까? – Gumbo
functionname === 'init' – Cofey