在得到了 env对象后,如何动态的让每个env对应一个函数,如以下代码所表示
在messenger对象的构造函数中把每个响应函数的名字注册
org.omus._Messenger = function () {
this.initEventDispatcher();
this.filters = new Array();
this.subscr = new Array();
var hd = new Object();
hd["msg.toServer"] = "handleError";
hd["customMsg"] = "handleCustomMsg";
hd["adminMsg"] = "handleAdminMsg";
hd["msg.subscr"] = "handleSubscribe";
hd["msg.unsubscr"] = "handleUnsubscribe";
hd["msg.unsubAll"] = "handleUnsubscribeAll";
this.handlers = hd;
}
org.omus._Messenger.prototype.handleMessage = function (env) {
var mName = this.handlers[env.getType()];
if (mName == undefined) {
org.omus.iLog.error("clj-050","envelope = " + env);
return;
}
this[mName](env);
}