< script language = " JavaScript " >
ExpandedBlockStart.gif
/*
InBlock.gif * 演示arguments的用法,如何获取实参数和形数数
ExpandedBlockEnd.gif 
*/

ExpandedBlockStart.gif
function  argTest(a,b,c,d) {
InBlock.gif    
var numargs = arguments.length;     // 获取被传递参数的数值。
InBlock.gif
    var expargs = argTest.length;       // 获取期望参数的数值。
InBlock.gif
    alert("实参数目为:"+numargs)
InBlock.gif    alert(
"形数数目为:"+expargs)
InBlock.gif
InBlock.gif    alert(arguments[
0])         
InBlock.gif    alert(argTest[
0])          //undefined 没有这种用法
ExpandedBlockEnd.gif
}

None.gif
// argTest(1,2)
None.gif//
argTest(1,2,3,4,5)
None.gif

ExpandedBlockStart.gif
/*
InBlock.gif *  arguments不是数组(Array类)
ExpandedBlockEnd.gif 
*/

None.gif
None.gifArray.prototype.selfvalue 
=   1 ;
ExpandedBlockStart.gif
function  testAguments() {
InBlock.gif    alert(
"arguments.selfvalue="+arguments.selfvalue);
ExpandedBlockEnd.gif}

None.gif
// alert("Array.sefvalue="+new Array().selfvalue);
None.gif//
testAguments();
None.gif

None.gif
None.gif
None.gif
None.gif
ExpandedBlockStart.gif
/*
InBlock.gif * 演示函数的caller属性.
InBlock.gif * 说明:(当前函数).caller:返回一个对函数的引用,该函数调用了当前函数
ExpandedBlockEnd.gif 
*/

None.gif
ExpandedBlockStart.gif
function  callerDemo()  {
ExpandedSubBlockStart.gif    
if (callerDemo.caller) {
InBlock.gif        
var a= callerDemo.caller.arguments[0];
InBlock.gif        alert(a);
ExpandedSubBlockStart.gif    }
 else {
InBlock.gif        alert(
"this is a top function");
ExpandedSubBlockEnd.gif    }

ExpandedBlockEnd.gif}

ExpandedBlockStart.gif
function  handleCaller()  {
InBlock.gif    callerDemo();
ExpandedBlockEnd.gif}

None.gif
None.gif
// callerDemo();
None.gif//
handleCaller("参数1","参数2");
None.gif

None.gif
ExpandedBlockStart.gif
/*
InBlock.gif * 演示函数的callee属性.
InBlock.gif * 说明:arguments.callee:初始值就是正被执行的 Function 对象,用于匿名函数
ExpandedBlockEnd.gif 
*/

ExpandedBlockStart.gif
function  calleeDemo()  {
InBlock.gif    alert(arguments.callee);
ExpandedBlockEnd.gif}

None.gif
// calleeDemo();
None.gif//
(function(arg0,arg1){alert("形数数目为:"+arguments.callee.length)})();
None.gif

None.gif
ExpandedBlockStart.gif
/*
InBlock.gif * 演示apply,call函数的用法
InBlock.gif * 说明:作用都是将函数绑定到另外一个对象上去运行,两者仅在定义参数方式有所区别:
InBlock.gif *       apply(thisArg,argArray);
InBlock.gif *     call(thisArg[,arg1,arg2…] ]);
InBlock.gif *     即所有函数内部的this指针都会被赋值为thisArg
ExpandedBlockEnd.gif 
*/

None.gif
ExpandedBlockStart.gif 
function  ObjectA() {
InBlock.gif    alert(
"执行ObjectA()");
InBlock.gif    alert(arguments[
0]);
ExpandedSubBlockStart.gif    
this.hit=function(msg){alert(msg)}
InBlock.gif    
this.info="我来自ObjectA"
ExpandedBlockEnd.gif }

None.gif 
ExpandedBlockStart.gif 
function  ObjectB() {
InBlock.gif    alert(
"执行ObjectB()");
InBlock.gif    
//调用ObjectA()方法,同时ObjectA构造函数中的所有this就会被ObjectB中的this替代
InBlock.gif
    ObjectA.apply(this,arguments);//ObjectA.call(this);
InBlock.gif
    alert(this.info);
ExpandedBlockEnd.gif }

None.gif 
// ObjectB('参数0');
None.gif

None.gif
None.gif 
var  value = " global 变量 " ;
ExpandedBlockStart.gif 
function  Obj() {
InBlock.gif    
this.value="对象!";
ExpandedBlockEnd.gif }

ExpandedBlockStart.gif 
function  Fun1() {
InBlock.gif    alert(
this.value);
ExpandedBlockEnd.gif }

None.gif 
// Fun1();
None.gif
  // Fun1.apply(window); 
None.gif
  // Fun1.apply(new Obj()); 
None.gif
</ script >