【发布时间】:2012-11-23 05:28:45
【问题描述】:
我有以下代码:
bindEvents: function() {
$('#weight').click($.proxy(function(){
this.changeWeight($('#weight').is(':checked'));
},this));
$('#produce').change($.proxy(function(){
this.changeProduce();
},this));
$('.help-gtin').click($.proxy(function(){
if ($('#help-gtin').is(':hidden')) {
$('#help-gtin').slideDown();
} else {
$('#help-gtin').slideUp();
}
this.refreshGtin();
},this);
$('[name="order_production"]').click($.proxy(function(){
this.changeProduction();
},this));
},
我如何减少这个重复代码$.proxy 调用,因为bindEvents 内的所有方法都需要在this 范围内调用?
【问题讨论】: