Why was the arguments.callee.caller property deprecated in JavaScript?

前端 未结 4 1129
死守一世寂寞
死守一世寂寞 2020-11-22 05:57

Why was the arguments.callee.caller property deprecated in JavaScript?

It was added and then deprecated in JavaScript, but it was omitted altogether by

4条回答
  •  北荒
    北荒 (楼主)
    2020-11-22 06:48

    It is better to use named functions than arguments.callee:

     function foo () {
         ... foo() ...
     }
    

    is better than

     function () {
         ... arguments.callee() ...
     }
    

    The named function will have access to its caller through the caller property:

     function foo () {
         alert(foo.caller);
     }
    

    which is better than

     function foo () {
         alert(arguments.callee.caller);
     }
    

    The deprecation is due to current ECMAScript design principles.

提交回复
热议问题