2014-11-13 2 views
1

here is a good explication은 런타임 함수와 구문 분석 시간의 차이점을 발견했습니다. 내가 할 노력하고있어 비트는이JS 런타임 함수 내부에서 문자열을 사용하여 함수 호출

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

같은 그리고 난 사전에

start.window[funtionName]() 

덕분에 같은 함수 변수 'functionInside', 뭔가를 호출 할!

답변

1

필요에 따라 몇 가지 방법이 있습니다.

는 다음 두 가지 예 :

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

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

여기에 또 다른 접근 방식 :

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

var s = new start(); 

s[funtionName](); //different ways to invoke 
s.functionInside(); 
+0

은 내가 전화이었다 기능을 알고 싶다면? –

+0

conole.log를 추가하거나 다른 영역에서 경고를 볼 수 있습니다. 또는 크롬에서 코드를 추적 할 수 있도록 중지를 추가합니다. –