トピックのタイトルが良くなくてすみません。名前の付け方がわからない。
この例について助けが必要です。完全に迷っています。
関数fillViewが呼び出されたときはすべて問題ありませんが、サイズ変更で2回目に呼び出されたときは機能しません。これは、レンダー関数内で「this」がウィンドウを定義しますが、localClassのインスタンスを定義しないためです。この問題を理解する方法の説明が必要です。例を書いてください。
(function ($) {
var localClass = function(options) {
this.a = 123;
};
localClass.prototype.render = function() {
console.log(this.a);
}
$.fn.fillView = function(options){
var view = new localClass(options);
view.render(); //this prints to console 123
$(window).resize(view.render); //this doesn't print 123
because 'this' is now - Window
}
})(jQuery)