From 95bfdf9b4d36daf74a31c8459baaa230739d35df Mon Sep 17 00:00:00 2001 From: rolux Date: Fri, 25 May 2012 13:00:40 +0200 Subject: [PATCH] rename vars; improved Ox.typeOf patch for Mobile Safari --- source/Ox/js/Type.js | 83 +++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 39 deletions(-) diff --git a/source/Ox/js/Type.js b/source/Ox/js/Type.js index f724bff4..9191beac 100644 --- a/source/Ox/js/Type.js +++ b/source/Ox/js/Type.js @@ -6,8 +6,8 @@ Ox.checkType Throws a TypeError if a value is not of a given type val <*> Any value type Type, or array of types @*/ -Ox.checkType = function(val, type) { - if (!Ox.contains(Ox.makeArray(type), Ox.typeOf(val))) { +Ox.checkType = function(value, type) { + if (!Ox.contains(Ox.makeArray(type), Ox.typeOf(value))) { throw new TypeError(); } }; @@ -19,8 +19,8 @@ Ox.isArguments Tests if a value is an arguments "array" > Ox.isArguments((function() { return arguments; }())) true @*/ -Ox.isArguments = function(val) { - return Ox.typeOf(val) == 'arguments'; +Ox.isArguments = function(value) { + return Ox.typeOf(value) == 'arguments'; }; /*@ @@ -34,8 +34,8 @@ Ox.isArray Tests if a value is an array > Ox.isArray({0: 0, length: 1}) false @*/ -Ox.isArray = function(val) { - return Ox.typeOf(val) == 'array'; +Ox.isArray = function(value) { + return Ox.typeOf(value) == 'array'; }; /*@ @@ -45,8 +45,8 @@ Ox.isBoolean Tests if a value is boolean > Ox.isBoolean(false) true @*/ -Ox.isBoolean = function(val) { - return Ox.typeOf(val) == 'boolean'; +Ox.isBoolean = function(value) { + return Ox.typeOf(value) == 'boolean'; }; /*@ @@ -56,8 +56,8 @@ Ox.isDate Tests if a value is a date > Ox.isDate(new Date()) true @*/ -Ox.isDate = function(val) { - return Ox.typeOf(val) == 'date'; +Ox.isDate = function(value) { + return Ox.typeOf(value) == 'date'; }; /*@ @@ -67,8 +67,8 @@ Ox.isElement Tests if a value is a DOM element > Ox.isElement(document.createElement('a')) true @*/ -Ox.isElement = function(val) { - return Ox.endsWith(Ox.typeOf(val), 'element'); +Ox.isElement = function(value) { + return Ox.endsWith(Ox.typeOf(value), 'element'); }; /*@ @@ -156,8 +156,8 @@ Ox.isFunction Tests if a value is a function > Ox.isFunction(/ /) false @*/ -Ox.isFunction = function(val) { - return Ox.typeOf(val) == 'function'; +Ox.isFunction = function(value) { + return Ox.typeOf(value) == 'function'; }; /*@ @@ -171,8 +171,8 @@ Ox.isInfinity Tests if a value is positive or negative Infinity > Ox.isInfinity(NaN) false @*/ -Ox.isInfinity = function(val) { - return Ox.typeOf(val) == 'number' && !isFinite(val) && !Ox.isNaN(val); +Ox.isInfinity = function(value) { + return Ox.typeOf(value) == 'number' && !isFinite(value) && !Ox.isNaN(value); }; /*@ @@ -184,8 +184,8 @@ Ox.isInt Tests if a value is an integer > Ox.isInt(0.5) false @*/ -Ox.isInt = function(val) { - return val === Math.floor(val); +Ox.isInt = function(value) { + return value === Math.floor(value); }; /*@ @@ -195,8 +195,8 @@ Ox.isNaN Tests if a value is NaN > Ox.isNaN(NaN) true @*/ -Ox.isNaN = function(val) { - return val !== val; +Ox.isNaN = function(value) { + return value !== value; } /*@ @@ -206,8 +206,8 @@ Ox.isNull Tests if a value is null > Ox.isNull(null) true @*/ -Ox.isNull = function(val) { - return Ox.typeOf(val) == 'null'; +Ox.isNull = function(value) { + return Ox.typeOf(value) == 'null'; }; /*@ @@ -223,8 +223,8 @@ Ox.isNumber Tests if a value is a number > Ox.isNumber(NaN) true @*/ -Ox.isNumber = function(val) { - return Ox.typeOf(val) == 'number'; +Ox.isNumber = function(value) { + return Ox.typeOf(value) == 'number'; }; /*@ @@ -242,8 +242,8 @@ Ox.isObject Tests if a value is a an object > Ox.isObject(/ /) false @*/ -Ox.isObject = function(val) { - return Ox.typeOf(val) == 'object'; +Ox.isObject = function(value) { + return Ox.typeOf(value) == 'object'; }; /*@ @@ -261,8 +261,8 @@ Ox.isPrimitive Tests if a value is a primitive (boolean, number or string) > Ox.isPrimitive({}) false @*/ -Ox.isPrimitive = function(val) { - var type = Ox.typeOf(val); +Ox.isPrimitive = function(value) { + var type = Ox.typeOf(value); return type == 'boolean' || type == 'number' || type == 'string'; }; @@ -273,8 +273,8 @@ Ox.isRegExp Tests if a value is a regular expression > Ox.isRegExp(/ /) true @*/ -Ox.isRegExp = function(val) { - return Ox.typeOf(val) == 'regexp'; +Ox.isRegExp = function(value) { + return Ox.typeOf(value) == 'regexp'; }; /*@ @@ -284,8 +284,8 @@ Ox.isString Tests if a value is a string > Ox.isString('') true @*/ -Ox.isString = function(val) { - return Ox.typeOf(val) == 'string'; +Ox.isString = function(value) { + return Ox.typeOf(value) == 'string'; }; /*@ @@ -295,8 +295,8 @@ Ox.isUndefined Tests if a value is undefined > Ox.isUndefined() true @*/ -Ox.isUndefined = function(val) { - return Ox.typeOf(val) == 'undefined'; +Ox.isUndefined = function(value) { + return Ox.typeOf(value) == 'undefined'; }; /*@ @@ -334,9 +334,14 @@ Ox.typeOf Returns the type of a value > Ox.typeOf() 'undefined' @*/ -Ox.typeOf = function(val) { - // Mobile Safari doesn't like null or undefined here - return val === null ? 'null' - : val === void 0 ? 'undefined' - : Object.prototype.toString.call(val).slice(8, -1).toLowerCase(); +Ox.typeOf = function(value) { + return Object.prototype.toString.call(value).slice(8, -1).toLowerCase(); }; +if (Ox.typeOf() != 'undefined') { + // Handle Mobile Safari + Ox.typeOf = function(value) { + return value === null ? 'null' + : value === void 0 ? 'undefined' + : Object.prototype.toString.call(value).slice(8, -1).toLowerCase(); + }; +}