看了网上的一篇文章<<全面理解javascript的caller,callee,call,apply概念>>,记下代码,备用
bubuko.com,布布扣<script language="JavaScript">
bubuko.com,布布扣/*
bubuko.com,布布扣 * 演示arguments的用法,如何获取实参数和形数数
bubuko.com,布布扣 */
bubuko.com,布布扣function argTest(a,b,c,d){
bubuko.com,布布扣    var numargs = arguments.length;     // 获取被传递参数的数值。
bubuko.com,布布扣    var expargs = argTest.length;       // 获取期望参数的数值。
bubuko.com,布布扣    console.log("实参数目为:"+numargs)
bubuko.com,布布扣   console.log("形数数目为:"+expargs)
bubuko.com,布布扣
bubuko.com,布布扣    console.log(arguments[0])         
bubuko.com,布布扣    console.log(argTest[0])          //undefined 没有这种用法
bubuko.com,布布扣}
bubuko.com,布布扣//argTest(1,2)
bubuko.com,布布扣//argTest(1,2,3,4,5)
bubuko.com,布布扣
bubuko.com,布布扣/*
bubuko.com,布布扣 *  arguments不是数组(Array类)
bubuko.com,布布扣 */
bubuko.com,布布扣
bubuko.com,布布扣Array.prototype.selfvalue = 1;
bubuko.com,布布扣function testAguments(){
bubuko.com,布布扣   console.log("arguments.selfvalue="+arguments.selfvalue);
bubuko.com,布布扣}
bubuko.com,布布扣//console.log("Array.sefvalue="+new Array().selfvalue);
bubuko.com,布布扣//testAguments();
bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣/*
bubuko.com,布布扣 * 演示函数的caller属性.
bubuko.com,布布扣 * 说明:(当前函数).caller:返回一个对函数的引用,该函数调用了当前函数
bubuko.com,布布扣 */
bubuko.com,布布扣
bubuko.com,布布扣function callerDemo() {
bubuko.com,布布扣    if (callerDemo.caller) {
bubuko.com,布布扣        var a= callerDemo.caller.arguments[0];
bubuko.com,布布扣       console.log(a);
bubuko.com,布布扣    } else {
bubuko.com,布布扣       console.log("this is a top function");
bubuko.com,布布扣    }
bubuko.com,布布扣}
bubuko.com,布布扣function handleCaller() {
bubuko.com,布布扣    callerDemo();
bubuko.com,布布扣}
bubuko.com,布布扣
bubuko.com,布布扣//callerDemo();
bubuko.com,布布扣//handleCaller("参数1","参数2");
bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣/*
bubuko.com,布布扣 * 演示函数的callee属性.
bubuko.com,布布扣 * 说明:arguments.callee:初始值就是正被执行的 Function 对象,用于匿名函数
bubuko.com,布布扣 */
bubuko.com,布布扣function calleeDemo() {
bubuko.com,布布扣   console.log(arguments.callee);
bubuko.com,布布扣}
bubuko.com,布布扣//calleeDemo();
bubuko.com,布布扣//(function(arg0,arg1){console.log("形数数目为:"+arguments.callee.length)})();
bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣/*
bubuko.com,布布扣 * 演示apply,call函数的用法
bubuko.com,布布扣 * 说明:作用都是将函数绑定到另外一个对象上去运行,(在特定作用域内调用函数实际上等于设置函数体内的this值)两者仅在定义参数方式有所区别:
bubuko.com,布布扣 *       apply(thisArg,argArray); 
bubuko.com,布布扣 *     call(thisArg[,arg1,arg2…] ]);
bubuko.com,布布扣 *     即所有函数内部的this指针都会被赋值为thisArg
bubuko.com,布布扣 */
bubuko.com,布布扣
bubuko.com,布布扣 function ObjectA(){
bubuko.com,布布扣    console.log("执行ObjectA()");
bubuko.com,布布扣    alert(arguments[0]);
bubuko.com,布布扣    this.hit=function(msg){alert(msg)}
bubuko.com,布布扣    this.info="我来自ObjectA"
bubuko.com,布布扣 }
bubuko.com,布布扣 
bubuko.com,布布扣 function ObjectB(){
bubuko.com,布布扣    alert("执行ObjectB()");
bubuko.com,布布扣    //调用ObjectA()方法,同时ObjectA构造函数中的所有this就会被ObjectB中的this替代
bubuko.com,布布扣    ObjectA.apply(this,arguments);//ObjectA.call(this);
bubuko.com,布布扣    alert(this.info);
bubuko.com,布布扣 }
bubuko.com,布布扣 //ObjectB(‘参数0‘);
bubuko.com,布布扣
bubuko.com,布布扣
bubuko.com,布布扣 var value="global 变量";
bubuko.com,布布扣 function Obj(){
bubuko.com,布布扣    this.value="对象!";
bubuko.com,布布扣 }
bubuko.com,布布扣 function Fun1(){
bubuko.com,布布扣    alert(this.value);
bubuko.com,布布扣 }
bubuko.com,布布扣 //Fun1();
bubuko.com,布布扣 //Fun1.apply(window); 
bubuko.com,布布扣 //Fun1.apply(new Obj()); 
bubuko.com,布布扣</script>