Yesterday, Adan sent me a javascript reload example. It feels good. Although I still don't quite understand how to implement it, I posted it.
Implement setTimeout to pass object objects
See the following code to transmit parameters to the function in.
<Script type = "text/javascript">
Var _ st = window. setTimeout;
Window. setTimeout = function (fRef, mDelay ){
If (typeof fRef = 'function '){
Var argu = Array. prototype. slice. call (arguments, 2 );
Var f = (function () {fRef. apply (null, argu );});
Return _ st (f, mDelay );
}
Return _ st (fRef, mDelay );
}
Function test (x ){
Alert (x );
}
Window. setTimeout (test, 1000, 'fason ');
</Script>
Call method description in JScript reference: call a method of an object to replace the current object with another object. Call ([thisObj [, arg1 [, arg2 [, [,. argN]), but no example
Description of the apply method JScript reference: apply a method of an object and replace the current object with another object. Apply ([thisObj [, argArray])
In fact, these two functions are almost the same. Note that the arg parameter in call (thisObj [, arg1 [, arg2 [,) can be a variable, the parameters in apply ([thisObj [, argArray]) are array sets.
This morning I saw another example of using call to implement inheritance. I also posted it together. This example is relatively simple.
<Script language = "javascript" type = "text/javascript">
Function father () {// parent class
Var self = this; // Private variable, which is not inherited in the subclass!
Var var_private = "private variable"; // private variable
This. var_public = "public variable"; // public variable
This. author = "xling ";
This. test = function (msg) {// public Method
Alert ("this method is located in the parent class:" + msg + "\ n" + self. author );
}
Var test2 = function () {// Private method, which cannot be called by subclass
Alert ("this method is a private method of the parent class ");
}
}
Function father2 (){
This. email = "xlingFairy # hotmail.com ";
}
Function suber () {// subclass
Father. call (this); // inherit the visible variables and methods (this) of the parent class through this sentence)
}
Function sun (){
Suber. call (this );
Father2.call (this); // put it together with the above sentence to implement multiple commitments! Awesome!
}
Var mySuber = new suber ();
MySuber. test ("the parameter is passed in from the subclass instance ");
// MySuber. test2 (); // The error code is returned because test2 is the private class of the parent class.
Alert ("private variable of the parent class. The subclass cannot read:" + mySuber. var_private );
Alert ("public variables of the parent class, which can be read by sub-classes" + mySuber. var_public );
Var mySun = new sun ();
MySun. test ("this is a parameter passed in from a grandson-level instance ");
Alert ("private variable of the parent class, which cannot be read by sub-classes:" + mySun. var_private );
Alert ("public variables of the parent class, which can be read by sub-classes" + mySun. var_public );
Alert (mySun. email );
</Script>