一些ExtJS组件在配置回调函数的时候只是提供函数名而并没有传入实参,如下面callback中的形参id,msg:Ext.onReady(function(){
Ext.MessageBox.prompt('提示','请在此输入内容:',callback,this,true); function callback(id,msg){
alert('单击的按钮id是:'+id+'\n'+'输入的内容是:'+msg);
}
})
还有在创建一个日期菜单时onClickDate的形参dm,date: menu: new Ext.menu.DateMenu({
handler:onClickDate;
}
)
function onClickDate(dm,date){
alert(date.format('Y-m-d'));
}
请问ExtJS是如何识别实参和形参的配对呢?是ExtJS已经对这些特定的组件规定好其回调函数的参数吗?
Ext.MessageBox.prompt('提示','请在此输入内容:',callback,this,true); function callback(id,msg){
alert('单击的按钮id是:'+id+'\n'+'输入的内容是:'+msg);
}
})
还有在创建一个日期菜单时onClickDate的形参dm,date: menu: new Ext.menu.DateMenu({
handler:onClickDate;
}
)
function onClickDate(dm,date){
alert(date.format('Y-m-d'));
}
请问ExtJS是如何识别实参和形参的配对呢?是ExtJS已经对这些特定的组件规定好其回调函数的参数吗?
比如 Class Ext.MessageBox 的 Example usage 里有回调函数示例
Defined In: DateMenu.js
Class: DateMenu
Extends: Menu
xtype: datemenu Config Options:handler : Function
Optional. A function that will handle the select event of this menu. The handler is passed the following parameters:...
Optional. A function that will handle the select event of this menu. The handler is passed the following parameters:
picker : DatePicker
The Ext.DatePicker.
date : Date
The selected date.
http://www.extjs.com/deploy/dev/docs/
实参:picker ()类型:DatePicker
实参:date(你选择的日期)类型:Date
menu: new Ext.menu.DateMenu({
handler:onClickDate;
}
的实参是隐式的,
我们在回调函数中用的都是形参