diff --git a/test/functions.js b/test/functions.js index 3c9f6a2c1..230ebea9a 100644 --- a/test/functions.js +++ b/test/functions.js @@ -52,6 +52,13 @@ $(document).ready(function() { var fastFib = _.memoize(fib); equals(fib(10), 55, 'a memoized version of fibonacci produces identical results'); equals(fastFib(10), 55, 'a memoized version of fibonacci produces identical results'); + + var o = function(str) { + return str; + }; + var fastO = _.memoize(o); + equals(o('toString'), 'toString', 'checks hasOwnProperty'); + equals(fastO('toString'), 'toString', 'checks hasOwnProperty'); }); asyncTest("functions: delay", 2, function() { diff --git a/underscore.js b/underscore.js index 4a9400d7c..343f335be 100644 --- a/underscore.js +++ b/underscore.js @@ -426,7 +426,7 @@ hasher = hasher || _.identity; return function() { var key = hasher.apply(this, arguments); - return key in memo ? memo[key] : (memo[key] = func.apply(this, arguments)); + return hasOwnProperty.call(memo, key) ? memo[key] : (memo[key] = func.apply(this, arguments)); }; };