使用 JQuery,您可以随时创建任何类型的事件并将其附加到您想要的任何对象。
function Graph (dataType, provider){
this.dataType = dataType;
this.provider = provider;
}
var g = new Graph;
g.dataType = "whatever1";
g.provider = "whatever2";
g.event = $.Event("mywhateverEvent");
g.myOwnProperty2 = $.Event("thisisAnEventToo");
现在您可以进一步操作您的事件,对事件做任何您想做的事情,使用类似:
g.event = <whateverCodeIWant>;
g.myOwnProperty2 = <whateverCodeIwant2>
由于您似乎喜欢构造函数,因此您也可以这样做:
function Graph (dataType, provider, evt){
this.dataType = dataType;
this.provider = provider;
this.evt = evt
}
var myevt = $.Event("whateverEvent");
myevt = <codeTomanipulatemyEventFurtherNowIfIWantTo>;
var g = new Graph("datawhatever", "providerwhatever", myevt);
$("whateverIWant").bind(myevt);
//or whatever other binding - it will bind to that very event
$("whateverIWant").bind(g.evt);//equivalent to above line- binds to same event object