Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- is = {
- fun:function(obj){ return typeof obj === "function" },
- obj:function(obj){ return typeof obj === "object" },
- arr:function(obj){ return obj.constructor.toString().slice(9,12) === "Arr" }
- };
- types = {};
- function capitaliseFirstLetter(string)
- {
- return string.charAt(0).toUpperCase() + string.slice(1);
- }
- function clos(k)
- {
- var _is = is;
- return function(value)
- {
- if ( !_is[k](value) )
- {
- throw "value \"{value}\" has not type \"{type}\" ".replace('{value}', value.toString()).replace('{type}', k);
- }
- return true;
- };
- }
- var i;
- for (i in is)
- {
- if ( !is.hasOwnProperty(i) )continue;
- types[ "is" + capitaliseFirstLetter(i) ] = is[i];
- types[ "check" + capitaliseFirstLetter(i) ] = clos(i);
- }
Advertisement
Add Comment
Please, Sign In to add comment