zoukankan      html  css  js  c++  java
  • javascript 中的 arguments,callee.caller,apply,call 区别

    记录一下:

    1.arguments是一个对象, 是函数的一个特性,只有在函数内才具有这个特性,在函数外部不用使用。

    举例:

    function test(){
      alert(typeof arguments); //object 
    }
    
     alert(typeof arguments);  //undefined
    

    2.callee,caller

     callee 表示当前正在使用的函数,例如 arguments.callee 表示test

     caller 表示当前函数的调用者,如果在最顶层 那么就为 null ,如 test() 为 null ;test2() 为test

    function test(){
        alert(arguments.callee);
        alert(arguments.callee.caller);
    }
    function test2(){
        test();
    }
    test();
    test2();
    

    3.apply,call

    是函数原型的一个方法,调用者的类型必须是函数。官方解释:应用某一对象的一个方法,用另一个对象替换当前对象。简单的讲,就是对象置换

    apply和call的区别:方法传递的参数不同

      fun.call(this, arg1,arg2,arg3) == fun.apply(this, arguments)==this.fun(arg1, arg2, arg3)

      

      

  • 相关阅读:
    Matlab---绘制柱状图
    认识Caffe与Caffe2
    Matlab---绘图及其位置摆放
    Matlab---三维视图的自动旋转
    Matlab---读取 .txt文件
    Matlab---画图线型、符号及颜色
    day 28 黏包及黏包解决方案
    day 27
    day 26 网络知识 01
    day 25 模块与包
  • 原文地址:https://www.cnblogs.com/yupeng/p/2675606.html
Copyright © 2011-2022 走看看