Prototype パターンを使用して、Web コントロール用のクライアント側 API を作成しようとしています。しかし、「これ」を管理しなくて済むようにして、生活を楽にしたい。
これはいくつかのサンプル コードです (問題のある行をコメントしました):
MyObject = function ()
{
MyObject.initializeBase(this);
this._someProperty = null;
};
MyObject.prototype = {
initialize: function()
{
// Init
},
get_someProperty: function()
{
return this._someProperty;
},
set_someProperty: function(value)
{
this._someProperty = value;
},
doSomething: function ()
{
$('.some-class').each(function ()
{
$(this).click(this.doClick); // this.doClick is wrong
});
},
doClick: function ()
{
alert('Hello World');
}
};
通常、公開モジュール パターンを使用して、プライベート変数を宣言します。
var that = this;
Prototype パターンで同様のことを行うことはできますか?