arguments对象是比较特别的一个对象,arguments非常类似Array,但实际上又不是一个Array实例。

它指的是函数对象里的参数,且只能在函数内部使用。

使用

  检测函数的参数个数,引用属性 arguments.length。

  访问:arguments[0]

1.arguments对象的长度是由实参个数而不是形参个数决定的。

function a(a,b,c){
  console.log(arguments.length)
  console.log(arguments[3])
  b=b-a;
  console.log(b)
}
a(1,2);//2 undefined 1

2.JavaScript中函数是不能重载的。

如何实现重载呢?

function fn(){
switch(arguments.length){
case 0:
//执行语句块
break;
case 1:
//执行语句块
break;
case 2:
//执行语句块
break;
}
}

3.arguments对象中有一个非常有用的属性:callee。arguments.callee返回此arguments对象所在的当前函数引用。在使用函数递归调用时推荐使用arguments.callee代替函数名本身。

function a(a){
if(a==1){return 1}
return a+arguments.callee(--a);
}
a(10);//
function ass(a,b,s){
console.log(arguments.callee.length);
console.log(arguments.length);
}
assl(1,2);//3 2

arguments.length是实参长度,arguments.callee.length是形参长度

caller 返回一个函数的引用,这个函数调用了当前的函数。

使用这个属性要注意:

1 这个属性只有当函数在执行时才有用
2 如果在javascript程序中,函数是由顶层调用的,则返回null

function b(){
a()
}
function a(){
alert(a===arguments.callee);//true
alert(arguments.caller=b);//function b(){a()}
alert(arguments.callee.caller===b);//true
}
b();
var a = function() {
alert(a.caller); //null
}
a();

 var a = function() {
      alert(arguments.callee);
 }
 a();//var a = function() { alert(arguments.callee); }

 

arguments对象,caller 和 callee的更多相关文章

  1. 【转】JavaScript 之arguments、caller 和 callee 介绍

    1.前言 arguments, caller ,   callee 是什么? 在JavaScript 中有什么样的作用?本篇会对于此做一些基本介绍. 本文转载自:http://blog.csdn.ne ...

  2. JavaScript 之arguments、caller 和 callee 介绍

    1.前言 arguments, caller ,   callee 是什么? 在javascript 中有什么样的作用?本篇会对于此做一些基本介绍. 2. arguments arguments:  ...

  3. jacascript 函数参数与 arguments 对象

    前言:这是笔者学习之后自己的理解与整理.如果有错误或者疑问的地方,请大家指正,我会持续更新! 调用函数时,实参和形参需要一一对应,但如果参数多了的话,会很苦恼: 我们可以用键值对(字面量对象)的方式传 ...

  4. 使用 arguments 对象

    arguments 对象表示参数集合,它是一个伪类数组,拥有与数组相似的结构,可以通过数组下标的形式访问函数实参值,但是没有基础 Array 的原型方法. //函数没有定义形参,但是在函数体内通过 a ...

  5. arguments对象的callee属性和caller属性

    js中的arguments对象代表正在执行的函数和调用它的函数的参数.arguments对象有两个属性,callee和caller.collee表示当前正在执行的方法,caller表示调用该方法的对象 ...

  6. arguments.callee 调用自身 caller,callee,apply and call

    一.Arguments该对象代表正在执行的函数和调用他的函数的参数.[function.]arguments[n]参数function :选项.当前正在执行的 Function 对象的名字.n :选项 ...

  7. arguments.callee 属性 递归调用 & caller和callee的区别

    arguments.callee   在函数内部,有两个特殊的对象:arguments 和 this.其中, arguments 的主要用途是保存函数参数, 但这个对象还有一个名叫 callee 的属 ...

  8. arguments对象的callee属性详解

    在函数内部,有两个特殊的对象:arguments和this. argument对象有一个名叫callee的属性,该属性是一个指针,指向拥有这个arguments对象的函数.请看下面这个非常经典的阶乘函 ...

  9. js中的caller和callee属性

    caller返回一个对函数的引用,该函数调用了当前函数. functionName.caller functionName 对象是所执行函数的名称. 说明对于函数来说,caller 属性只有在函数执行 ...

随机推荐

  1. 每天点滴的进行,css+div简单布局...布局

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  2. C#与C++中struct和class的小结

    在C#中,struct其实也是可以像class一样封装方法和数据的.请参考如下代码. using System; namespace testDiffInStructClass { public st ...

  3. 手动安装VS code 插件

    现在安装包: 通过修改下面的地址参数:https://${publisher}.gallery.vsassets.io/_apis/public/gallery/publisher/${publish ...

  4. Java中 +=是什么意思 什么情况下用

    x+=1与x=x+1一样的效果执行一次x=x+1,就等于给x重新赋了值,这个值就是x+1例如:int x=1;x+=1;最后x的值是2x+=1一般在循环下使用,能发挥它的最大的作用.例如:while( ...

  5. 怎样取json对应的值

    { "轮胎1":[{"数量": "1","型号": "195 65R15","售价&quo ...

  6. 关于指针要注意的地方还有尝试在codeblocks上建立项目

    1.字符串: char a[]="house"; char *b="house"; a[2]='r';可以   b[2]='r'不可以,因为这个指针变量指的是字 ...

  7. VS编译wxWidgets

    准备工作 下载wxWidgets源码包(官网),我用的是3.02版: 安装Visual Studio.我用的是VS 2015 RC: 编译源码 解压wxWidgets的源码包,会得到一大堆文件.进入b ...

  8. selenium自动化遇见Cannot find class in classpath问题

    今天遇见了Cannot find class in classpath的问题, org.testng.TestNGException: Cannot find class in classpath: ...

  9. <button>与<input type="button"> 的区别

    <button> button按钮点击会刷新整个页面 <input type="button">  不会刷新整个页面 本文为本人用来记录自己做的一些东西,如 ...

  10. turn to help

    1 'On The Exact Recovery Condition of Simultaneous Orthogonal Matching Pursuit', JF Determe,J Louvea ...