Its syntax is:
Window. setTimeout (expr, msec)
Expr is the execution string and will run as js after msec milliseconds. I discovered yesterday that expr can also be a function. With this feature, you can transfer objects.
The following code implements the function to transmit the object p in function foo1 to function foo2.
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Currently, many frameworks directly adopt a multi-vote event (its implementation principle is not complicated). A multi-vote event itself is actually a standard function, but it generally has the following methods.
MuEvent. add = function (func ){...}
MuEvent. addMethod = function (instance, func ){...}
When the first method is used, when the func event handler function is activated, the current instance of MuEvent is the this object; the second method uses the passed instance as the this object.
Therefore, for setTimeout, our traditional method should use it to activate the method as follows:
----------
Function doTimer (){
Obj1.call ();
Obj2.call ();
}
SetTimeout (doTimer, 1000 );
The code for using multiple-vote events can be as follows:
----------
Var e = new MuEvent ();
E. addMethod (obj1, obj1.call );
E. addMethod (obj2, obj2.call );
SetTimeout (e, 1000 );
----------
Of course, you want to write a COOL point, which can be like this:
----------
SetTimeout (function (){
Return new MuEvent (obj1, obj1.call, obj2, obj2.call );
} (), 1000 );
----------
As a little introduction, Qomo is implemented in this form of MuEvent. Most frameworks like Atlas adopt similar methods.