typeArray.js 599 B

1234567891011121314151617181920212223242526272829303132
  1. "use strict";
  2. // benchmark ways to check if is an Array
  3. // setup
  4. var arr = [],
  5. objToStr = Object.prototype.toString,
  6. getTypeStr = function getTypeStr2(obj) {
  7. return objToStr.call(obj);
  8. };
  9. // tests
  10. exports.typeArray = {
  11. "getTypeStr (Object#toString.call)": function() {
  12. getTypeStr(arr) === "[object Array]";
  13. },
  14. "instanceof check": function() {
  15. arr instanceof Array;
  16. },
  17. "typeof check, constructor check": function() {
  18. typeof arr === "object" && arr.constructor === Array;
  19. },
  20. };
  21. // if run directly run benchmarks
  22. if (!module.parent) require("benchmarksman").runner(exports);