typeObjectLoose.js 526 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. // benchmark ways to check if is an Object of some sort
  3. // setup
  4. var Thing = function Thing() {},
  5. thing = new Thing();
  6. // tests
  7. exports.typeObject = {
  8. "instanceof check": function() {
  9. thing instanceof Object;
  10. },
  11. "null check, typeof check": function() {
  12. thing !== null && typeof thing === "object";
  13. },
  14. "typeof check, null check": function() {
  15. typeof thing === "object" && thing !== null;
  16. },
  17. };
  18. // if run directly run benchmarks
  19. if (!module.parent) require("benchmarksman").runner(exports);