diff --git a/test/objects.js b/test/objects.js index 48971c079..78add1fed 100644 --- a/test/objects.js +++ b/test/objects.js @@ -22,6 +22,10 @@ $(document).ready(function() { test("objects: functions", function() { var obj = {a : 'dash', b : _.map, c : (/yo/), d : _.reduce}; ok(_.isEqual(['b', 'd'], _.functions(obj)), 'can grab the function names of any passed-in object'); + + var Animal = function(){}; + Animal.prototype.run = function(){}; + equals(_.functions(new Animal).join(''), 'run', 'also looks up functions on the prototype'); }); test("objects: extend", function() { diff --git a/underscore.js b/underscore.js index 5757609fa..9857159eb 100644 --- a/underscore.js +++ b/underscore.js @@ -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).