Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Adding prototypes new getClass function. Changed JsUnitTest#inspect o…

…bject detection to use it.
  • Loading branch information...
commit fbf544339388063b5cc9fa29541aa968c0518438 1 parent 10e660e
@kristopher kristopher authored
Showing with 12 additions and 4 deletions.
  1. +12 −4 src/common.js
View
16 src/common.js
@@ -13,7 +13,7 @@ var JsUnitTest = {
if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
return "'" + escapedString.replace(/'/g, '\\\'') + "'";
};
- if ((typeof object == 'object') && (object.constructor == Object)) { // its probably an object.
+ if (JsUnitTest.getClass(object) === 'Object') {
var keys_values = new Array(), prefix = 'Object: { ';
for (property in object) {
keys_values.push(property + ': ' + object[property]);
@@ -26,7 +26,13 @@ var JsUnitTest = {
throw e;
}
},
- $: function(element) {
+
+ getClass: function(object) {
+ return Object.prototype.toString.call(object)
+ .match(/^\[object\s(.*)\]$/)[1];
+ },
+
+ $: function(element) {
if (arguments.length > 1) {
for (var i = 0, elements = [], length = arguments.length; i < length; i++)
elements.push(this.$(arguments[i]));
@@ -36,7 +42,8 @@ var JsUnitTest = {
element = document.getElementById(element);
return element;
},
- gsub: function(source, pattern, replacement) {
+
+ gsub: function(source, pattern, replacement) {
var result = '', match;
replacement = arguments.callee.prepareReplacement(replacement);
@@ -185,7 +192,8 @@ var JsUnitTest = {
return match;
},
- toQueryParams: function(query, separator) {
+
+ toQueryParams: function(query, separator) {
var query = query || window.location.search;
var match = query.replace(/^\s+/, '').replace(/\s+$/, '').match(/([^?#]*)(#.*)?$/);
if (!match) return { };

0 comments on commit fbf5443

Please sign in to comment.
Something went wrong with that request. Please try again.