Permalink
Browse files

Made the type checking function public

  • Loading branch information...
1 parent 219dd27 commit 9d62f5e93eb297bda990411ae3f912b8d6cfa4e9 Lea Verou committed May 7, 2011
Showing with 14 additions and 14 deletions.
  1. +14 −14 strongly-typed.js
View
28 strongly-typed.js
@@ -134,6 +134,19 @@ var self = window.StronglyTyped = {
});
o[name] = value;
+ },
+
+ /**
+ * Tests whether a value is of a given type
+ */
+ is: function(type, value) {
+ switch(type) {
+ case 'Integer':
+ return self.is('Number', value) && (isNaN(value) || !isFinite(value) || value % 1 === 0);
+ default:
+ return value instanceof window[type] ||
+ Object.prototype.toString.call(value) === '[object ' + type + ']';
+ }
}
};
@@ -166,7 +179,7 @@ function getter(property) {
* Generic setter
*/
function setter(type, property, value) {
- if (isType(type, value) || value === null || value === undefined) {
+ if (self.is(type, value) || value === null || value === undefined) {
getProperties(this)[property] = value;
}
else {
@@ -193,17 +206,4 @@ function getProperties(o) {
return objects[i].properties;
}
-/**
- * Tests whether a value is of a given type
- */
-function isType(type, value) {
- switch(type) {
- case 'Integer':
- return isType('Number', value) && (isNaN(value) || !isFinite(value) || value % 1 === 0);
- default:
- return value instanceof window[type] ||
- Object.prototype.toString.call(value) === '[object ' + type + ']';
- }
-}
-
})();

0 comments on commit 9d62f5e

Please sign in to comment.