2017-09-08 2 views
0

비디오 플레이어와 비디오 목록을 렌더링하는 뷰가 있습니다.백본에 인수 전달 .bind() function

initialize: function() { 
var q = window.location.search.slice(3); 
this.videos = new Videos(window.exampleVideoData); 
this.videos.bind('select', this.notifyAppView, this); 
if (q){ 
    this.videos.bind('fetchFinished', function(){ 
     console.log('should still work'); 
     this.render(); 
    }, this); 
    // Any time this.videos collection changes we will re-render 
    this.videoPlaying = this.videos.models[0]; 
    this.videos.fetch(q); 
}else{ 
    //Collection of all videos 

    // Any time this.videos collection changes we will re-render 
    this.videoPlaying = this.videos.models[0]; 
    this.render(); 
} 

},보기에 내 초기화 기능입니다

. 나는 점점 오전 문제는 내가 라인 bind 함수 오류

app.js:10 Uncaught SyntaxError: Unexpected string 

에 인수를 전달할 때

this.videos.bind('fetchFinished', function(){ 
    console.log('should still work'); 
    this.render(); 

}이); 우리가 같은 함수에 문자열을 통과 할 때

우리는 오류를 얻을 :

this.videos.bind('fetchFinished', function('adfadf'){ 
     console.log('should still work'); 
     this.render(); 
}, this); 

인수를 취 백본을 준수 할 수있는 기능을 지정하는 올바른 방법은 무엇입니까?

답변

2

구문이 올바르지 않습니다. 값이 아닌 함수 선언에 인수의 이름을 지정해야합니다.

이 같은 값을 전달할 수 있습니다

this.videos.bind('fetchFinished', function(arg){ 
    console.log('should still work', arg); // should still work adfadf 
    this.render(); 
}.bind(this, 'adfadf')); 

주 두 번째 bind는 함수 객체의 기본 bind 방법이 아닌 백본 bind이라고. 혼란을 피하기 위해 bind이라는 별칭을 사용하는 대신 백본의 on을 사용하는 것이 좋습니다.