typeArray.js 657 B

123456789101112131415161718192021222324252627282930313233343536
  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. "Array.isArray": function() {
  15. Array.isArray(arr);
  16. },
  17. "instanceof check": function() {
  18. arr instanceof Array;
  19. },
  20. "typeof check, constructor check": function() {
  21. typeof arr === "object" && arr.constructor === Array;
  22. },
  23. };
  24. // if run directly run benchmarks
  25. if (!module.parent) require("benchmarksman").runner(exports);