2013-11-21 3 views
0

저는 자바 스크립트에 초보자이며 자바 스크립트의 적용 기능을 테스트하는 샘플 함수를 만들었습니다.함수 적용 자바 스크립트 루핑 추가

는 I 그냥에 대입 궁금 코드에서 첫 번째 배열 [ 'VAL1' '을 val2'] 그러나 걸릴 -x

  1. 값을 명확하게 커플 필요 (이, X) ... 2.I 볼 3 항목이 CONSOLE.LOG에 인쇄되고, 마지막 항목 인 - 정의되지 않은, 정의되지 않은, 즉, 여기에 문제의 몇 가지가 있습니다

    var dummyfunction1 = function(val1,val2){ 
        console.log(array1,array2); 
    }; 
    
    [['val1','val2'],['val3','val4']].forEach(function(x){ 
        dummyfunction1.apply(this,x); 
    }); 
    
    dummyfunction1() 
    

답변

3

happends 무엇.

dummyfunction1은 본문에서 정의되지 않은 변수를 사용하고 있습니다. 그것은이 있어야합니다 : 마지막 줄 dummyfunction1() 매개 변수없이 dummyfunction1에 추가로 전화를하고있다

var dummyfunction1 = function(val1,val2){ 
    console.log(val1,val2); 
}; 

. 이것은보고있는 정의되지 않은 정의되지 않은 값입니다.

전체 코드는 다음과 같아야합니다

var dummyfunction1 = function(val1,val2){ 
    console.log(val1,val2); 
}; 

// this will automatically be run, no need to call dummyfunction1 on your own after this 
[['val1','val2'],['val3','val4']].forEach(function(x){ 
    dummyfunction1.apply(this,x); 
});