Issue #243. _.functions now also returns the names of function defined in the prototype chain.

This commit is contained in:
Jeremy Ashkenas
2011-07-13 11:09:51 -04:00
parent 727db393d5
commit cd236d4c47
2 changed files with 9 additions and 1 deletions

View File

@@ -559,7 +559,11 @@
// Return a sorted list of the function names available on the object.
// Aliased as `methods`
_.functions = _.methods = function(obj) {
return _.filter(_.keys(obj), function(key){ return _.isFunction(obj[key]); }).sort();
var names = [];
for (var key in obj) {
if (_.isFunction(obj[key])) names.push(key);
}
return names.sort();
};
// Extend a given object with all the properties in passed-in object(s).