<script language= "JavaScript" >
/*
* Demonstrate the use of arguments, how to get real parameters and number of shapes
*/
function Argtest (a,b,c,d){
var Numargs = arguments.length; Gets the numeric value of the passed parameter.
var Expargs = argtest.length; Gets the numeric value of the desired parameter.
Alert ("Real parameter:" +numargs)
Alert ("Number of shapes:" +expargs)
Alert (Arguments[0])
Alert (argtest[0])//undefined no such usage
}
Argtest (ON)
Argtest (1,2,3,4,5)
/*
* Arguments not arrays (array Class)
*/
Array.prototype.selfvalue = 1;
function testaguments (){
Alert ("arguments.selfvalue=" +arguments.selfvalue);
}
Alert ("Array.sefvalue=" +new Array (). Selfvalue);
Testaguments ();
/*
* Demonstrates the caller property of a function.
* Description: (current function). Caller: Returns a reference to the function that called the current function
*/
function Callerdemo (){
if (Callerdemo.caller){
var a= callerdemo.caller.arguments[0];
alert (a);
} else{
Alert ("This is a top function");
}
}
function Handlecaller (){
Callerdemo ();
}
Callerdemo ();
Handlecaller ("Parameter 1", "Parameter 2");
/*
* Demonstrates the callee property of a function.
* Description: Arguments.callee: The initial value is the function object being executed for the anonymous function
*/
function Calleedemo (){
alert (Arguments.callee);
}
Calleedemo ();
(function (ARG0,ARG1) {alert ("Number of shapes:" +arguments.callee.length)}) ();
/*
* Demonstrates the use of the Apply,call function
* Description: The role is to bind the function to another object to run, the two are only defined in the way the parameters differ:
* Apply (Thisarg,argarray);
* Call (Thisarg[,arg1,arg2 ...]);
* That is, the this pointer inside all functions will be assigned a value of Thisarg
*/
function Objecta (){
Alert ("Execute Objecta ()");
Alert (arguments[0]);
This.hit=function (msg){alert (msg)}
this.info= "I'm from Objecta"
}
function objectb () {
alert ("Executive OBJECTB ()");
//calls the Objecta () method, and all this in the Objecta constructor is replaced by this in OBJECTB
objecta.apply (this,arguments);//objecta.call (this);
alert (This.info);
}
&NBSP;//OBJECTB (' parameter 0 ');
var value= "global variable";
function obj () {
This.value= "Object! ";
}
function fun1 () {
alert (this.value);
}
//fun1 ();
//fun1.apply (window);
//fun1.apply (New obj ());
</script>