2017-09-08 1 views
0

私はビデオプレーヤーとビデオリストをレンダリングするビューを持っています。バックボーンに引数を渡す.bind()関数

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

}、ビューの私の初期化関数である

。私は取得しています問題は、私はラインでバインド機能、エラー

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

これは誤った構文です。引数ではなく、関数宣言で引数の名前を指定する必要があります。

次のような値で渡すことができます。第二bindは関数オブジェクトのネイティブbind方法ではなく、バックボーンbindであることを

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

注意。混乱を避けるために、別名bindを使用する代わりに、バックボーンのonを使用する方が良いでしょう。

関連する問題