如何为回调函数添加参数?

时间:2015-05-19 09:30:48

标签: javascript jquery

renderingContent:function(widget){
    uilayer.confirm("", this.renderingContextWidgetOnOkClick,this.contextChangeCancelHandler);
}

renderingContextWidgetOnOkClick:function(widget){
        console.log(widget);
}

如何将我在renderContent函数中获得的widget参数传递给回调this.renderingContextWidgetOnOkClick,点击OK后调用它,因为我无法调用this.renderingContextWidgetOnOkClick(widget),因为这个函数直接被调用而没有单击? / p>

1 个答案:

答案 0 :(得分:3)

您可以将其包装在函数中

renderingContent:function(widget){
    uilayer.confirm("",   
        (function(that, widget){ 
            return function(){
                that.renderingContextWidgetOnOkClick(widget);
            };            
        })(this, widget),this.contextChangeCancelHandler);
}