以下javascript构造是否有更好的替代方案?

时间:2011-04-21 11:38:39

标签: javascript jquery performance coding-style

以下代码模式是我如何构建我的AJAX系统。我担心何时添加更多原型属性。这可能会影响可维护性和效率。

是否有更好的替代方法可以为AJAX创建可维护且高效的构造?

function AjaxSample()
{
    //bindJS() is used to bind the 'this' pointer to the scope of the function
    $('#button_one').click(bindJS(this.button_oneEvent,this)); 
} 

AjaxSample.prototype.button_oneEvent = function(event)
{
    //code to handle the event
}

1 个答案:

答案 0 :(得分:1)

var self = this;
$('#button_one').click(function() {
    self.button_oneEvent();
}); 

使用这种技术,更明显的是实际发生的事情。

相关问题