dojo.connect解析

dojo.require("dojo._base.connect");

Connects method to event, so that after event fires, method does too. All connected functions are passed the same arguments as the event function was initially called with. You may connect as many methods to event as needed.

event must be a string. If obj is null, dojo.global is used.

 

null arguments may simply be omitted.

 

obj[event] can resolve to a function or undefined (null). If obj[event] is null, it is assigned a function.

The return value is a handle that is needed to remove this connection with dojo.disconnect.

 

parametertypedescription
objObject|nullThe source object for the event function. Defaults to dojo.global if null. If obj is a DOM node, the connection is delegated to the DOM event manager (unless dontFix is true).
eventStringname of the event function in obj. I.e. identifies a property obj[event].
contextObject|nullThe object that method will receive as "this". If context is null and method is a function, then method inherits the context of event. If method is a string then context must be the source object object for method (context[method]). If context is null, dojo.global is used.
methodString|FunctionA function reference, or name of a function in context. The function identified by method fires after event does. method receives the same arguments as the event. See context argument comments for information on method's scope.
dontFixBoolean

If obj is a DOM node, set dontFix to true to prevent delegation of this connection to the DOM event manager.

 


Usage

var foo=dojo.connect(obj Object|null, event String, context Object|null, method String|Function, dontFix Boolean);

Example 1

When obj.onchange(), do ui.update():

dojo.connect(obj, "onchange", ui, "update");
dojo.connect(obj, "onchange", ui, ui.update); // same

Example 2

Using return value for disconnect:

var link = dojo.connect(obj, "onchange", ui, "update");
...
dojo.disconnect(link);

Example 3

When onglobalevent executes, watcher.handler is invoked:

dojo.connect(null, "onglobalevent", watcher, "handler");

Example 4

When ob.onCustomEvent executes, customEventHandler is invoked:

dojo.connect(ob, "onCustomEvent", null, "customEventHandler");
dojo.connect(ob, "onCustomEvent", "customEventHandler"); // same

Example 5

When ob.onCustomEvent executes, customEventHandler is invoked with the same scope (this):

dojo.connect(ob, "onCustomEvent", null, customEventHandler);
dojo.connect(ob, "onCustomEvent", customEventHandler); // same

Example 6

When globalEvent executes, globalHandler is invoked with the same scope (this):

dojo.connect(null, "globalEvent", null, globalHandler);
dojo.connect("globalEvent", globalHandler); // same

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值