Ver Fonte

minor improvements to type examples

Kyle P Davis há 11 anos atrás
pai
commit
1f7a6f8ac4
3 ficheiros alterados com 26 adições e 10 exclusões
  1. 9 1
      example/typeArray.js
  2. 15 7
      example/typeIsExact.js
  3. 2 2
      example/typeObjectLoose.js

+ 9 - 1
example/typeArray.js

@@ -3,12 +3,20 @@
 
 
 // setup
-var arr = [];
+var arr = [],
+	objToStr = Object.prototype.toString,
+	getTypeStr = function getTypeStr2(obj) {
+		return objToStr.call(obj);
+	};
 
 
 // tests
 exports.typeArray = {
 
+	"getTypeStr (Object#toString.call)": function() {
+		getTypeStr(arr) === "[object Array]";
+	},
+
 	"instanceof check": function() {
 		arr instanceof Array;
 	},

+ 15 - 7
example/typeIsExact.js

@@ -3,25 +3,33 @@
 
 
 // setup
-function Thing() {}
-var thing = new Thing();
+var Thing = function Thing() {},
+	thing = new Thing(),
+	objToStr = Object.prototype.toString,
+	getTypeStr = function getTypeStr2(obj) {
+		return objToStr.call(obj);
+	};
 
 
 // tests
 exports.typeIsExact = {
 
-	"instanceof, constructor matches": function() {
-		thing instanceof Thing && thing.constructor === Thing;
+	"getTypeStr (Object#toString.call)": function() {
+		getTypeStr(thing) === "[object Function]";
 	},
 
-	"not undefined, not null, constructor matches": function() {
-		thing !== undefined && thing !== null && thing.constructor === Thing;
+	"instanceof, constructor matches": function() {
+		thing instanceof Thing && thing.constructor === Thing;
 	},
 
 	"truthy, constructor matches": function() {
 		thing && thing.constructor === Thing;
 	},
 
+	"not undefined, not null, constructor matches": function() {
+		thing !== undefined && thing !== null && thing.constructor === Thing;
+	},
+
 	"typeof, not null, constructor matches": function() {
 		typeof thing === "object" && thing !== null && thing.constructor === Thing;
 	},
@@ -30,4 +38,4 @@ exports.typeIsExact = {
 
 
 // if run directly run benchmarks
-if (!module.main) require("benchmarksman").runner(exports);
+if (!module.parent) require("benchmarksman").runner(exports);

+ 2 - 2
example/typeObjectLoose.js

@@ -3,8 +3,8 @@
 
 
 // setup
-function Thing() {}
-var thing = new Thing();
+var Thing = function Thing() {},
+	thing = new Thing();
 
 
 // tests