quick fix for 0.5.1 for IE -- need to define functions in the right order

This commit is contained in:
Jeremy Ashkenas
2009-12-09 14:36:19 -05:00
parent 4042a38dc6
commit a418153800
2 changed files with 18 additions and 23 deletions

View File

@@ -495,20 +495,15 @@
return typeof obj == 'undefined';
};
// isNumber needs to be defined before the rest of the isType functions,
// because _.each uses it in IE (and we want to use _.each for the closure).
_.isNumber = function(obj) {
return toString.call(obj) == '[object Number]';
};
// Define the isArray, isDate, isFunction, isRegExp, and isString functions
// based on their toString identifiers.
_.each(['Array', 'Date', 'Function', 'RegExp', 'String'], function(type) {
var identifier = '[object ' + type + ']';
_['is' + type] = function(obj) {
return toString.call(obj) == identifier;
};
});
// Define the isArray, isDate, isFunction, isNumber, isRegExp, and isString
// functions based on their toString identifiers.
var types = ['Array', 'Date', 'Function', 'Number', 'RegExp', 'String'];
for (var i=0, l=types.length; i<l; i++) {
(function() {
var identifier = '[object ' + types[i] + ']';
_['is' + types[i]] = function(obj) { return toString.call(obj) == identifier; };
})();
}
/* -------------------------- Utility Functions: -------------------------- */