diff --git a/index.html b/index.html index c6818b7a7..f2a00cae3 100644 --- a/index.html +++ b/index.html @@ -245,7 +245,7 @@
- getValue_.getValue(object, property)
+
+ result_.result(object, property)
Returns a value from an object as a property or as a function.
var object = {cheese: 'crumpets', stuff: function(){ return 'nonsense'; }};
-_.getValue(object, 'cheese');
+_.result(object, 'cheese');
=> "crumpets"
-_.getValue(object, 'stuff');
+_.result(object, 'stuff');
=> "nonsense"
diff --git a/test/utility.js b/test/utility.js index 5f2485478..ec9960eae 100644 --- a/test/utility.js +++ b/test/utility.js @@ -165,13 +165,13 @@ $(document).ready(function() { strictEqual(tmpl(), '
\u2028\u2028\u2029\u2029
'); }); - test('getValue calls functions and returns primitives', function() { + test('result calls functions and returns primitives', function() { var obj = {w: '', x: 'x', y: function(){ return 'y'; }}; - strictEqual(_.getValue(obj, 'w'), ''); - strictEqual(_.getValue(obj, 'x'), 'x'); - strictEqual(_.getValue(obj, 'y'), 'y'); - strictEqual(_.getValue(obj, 'z'), undefined); - strictEqual(_.getValue(null, 'x'), null); + strictEqual(_.result(obj, 'w'), ''); + strictEqual(_.result(obj, 'x'), 'x'); + strictEqual(_.result(obj, 'y'), 'y'); + strictEqual(_.result(obj, 'z'), undefined); + strictEqual(_.result(null, 'x'), null); }); }); diff --git a/underscore.js b/underscore.js index 24dcc72be..c00438cc5 100644 --- a/underscore.js +++ b/underscore.js @@ -874,7 +874,7 @@ }; // Get a value from an object as a property or as a function. - _.getValue = function(object, prop) { + _.result = function(object, prop) { if (object == null) return null; var value = object[prop]; return _.isFunction(value) ? value() : value;