Alternative isFunction Implementations

JavaScript performance comparison

Revision 25 of this test case created by

Preparation code

<script>
  var getClass = {}.toString,
      hasProperty = {}.hasOwnProperty,
      expression = /Kit/g;
  
  function Test() {}
  
  // Checks the internal [[Class]] name of the object.
  
  
  function isFunctionA(object) {
   return object && getClass.call(object) == '[object Function]';
  }
  
  // Partial duck-typing implementation by Garrett Smith.
  
  
  function isFunctionB(object) {
   if (typeof object != 'function') return false;
   var parent = object.constructor && object.constructor.prototype;
   return parent && hasProperty.call(parent, 'call');
  }
  
  // Pure duck-typing implementation taken from Underscore.js.
  
  
  function isFunctionC(object) {
   return !!(object && object.constructor && object.call && object.apply);
  }

  function isFunctionD(object) {
   return typeof object === 'function';
  }

  function isFunctionE(object) {
   return object instanceof Function;
  }
</script>
    

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
isFunctionA
isFunctionA(Test);
isFunctionA(getClass);
isFunctionA(hasProperty);
!isFunctionA(expression);
pending…
isFunctionB
isFunctionB(Test);
isFunctionB(getClass);
isFunctionB(hasProperty);
!isFunctionB(expression);
pending…
isFunctionC
isFunctionC(Test);
isFunctionC(getClass);
isFunctionC(hasProperty);
!isFunctionC(expression);
pending…
'isFunctionD'
isFunctionD(Test);
isFunctionD(getClass);
isFunctionD(hasProperty);
!isFunctionD(expression);
pending…
'isFunctionE'
isFunctionE(Test);
isFunctionE(getClass);
isFunctionE(hasProperty);
!isFunctionE(expression);
pending…

Compare results of other browsers

Revisions

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

0 Comments