Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

# chained "dojo.connect"s' parameter and execution order

Reported by: Owned by: yiqin yu high tbd General 1.6.0 dojo.connect, excution order

### Description

4 functions named a, b, c and d. They have relationships as follows: (1)when a is called, b is triggered; (2)when b is called, c is triggered; (3)when c is called, d is triggered.

Implemented by dojo.connect:

```function a(){console.log("a")};
function b(){console.log("b")};
function c(){console.log("c")};
function d(){console.log("d")};
dojo.connect(null, "c", null, d);  //Connect c to d need to be put firstly
dojo.connect(null, "b", null, c);
dojo.connect(null, "a", null, b);
a();
```

Then the output in console will be: a b c d

But once I do not follow the above execution order of dojo.connect and change the sequence, certain function will not work:

```dojo.connect(null, "a", null, b);
dojo.connect(null, "b", null, c);
dojo.connect(null, "c", null, d);
a();
```

The output in console is: a b

In which c & d is not successfully called.

Alternatively, if we change the forth parameter of each dojo.connect to string:

```dojo.connect(null, "a", null, "b");
dojo.connect(null, "b", null, "c");
dojo.connect(null, "c", null, "d");
a();
```

Then all functions are called successfully: a b c d

### Changed 10 years ago by yiqin yu

Attachment: test2.html​ added

### comment:1 Changed 10 years ago by Eugene Lazutkin

Resolution: → invalid new → closed

That's exactly how it is supposed to work with stand-alone functions. The explanation "why" is relatively long. Short answer: use the workaround you discovered: names vs. direct function references.

### comment:2 Changed 10 years ago by bill

I added a hopefully comprehensible explanation to http://docs.dojocampus.org/quickstart/events.

Note: See TracTickets for help on using tickets.