this.constructor vs. arguments.callee (in a constructor)

Benchmark created by humanchimp on


Description

this is kind of wtf, since referring to arguments.callee is always going to refer to the current function, whereas this.constructor is going to refer to the .constructor property of "this" (whatever that may be)... I don't mean to imply that they are equivalent actions... and it is well-known that "arguments.callee" is deprecated and slow.

Update: Added the third case. Not equivalent this.constructor, but fyi it is more or less equivalent to saying "arguments.callee" (and faster). I guess the only time you might actually "need" arguments.callee is for recursion in an anonymous function (hint: give the function an identifier).

Preparation HTML

<script>
  function Foo(){
    arguments.callee;
  }
  
  function Bar(){
    this.constructor;
  }
  
  function Baz(){
    Baz;
  }
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
arguments.callee
new Foo
ready
this.constructor
new Bar
ready
just refer to the damn thing by name
new Baz
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by humanchimp on