From 5c7ccb21ef5404dbbf4d925d03f35e49967e9a3a Mon Sep 17 00:00:00 2001 From: Brad Dunbar Date: Mon, 19 Mar 2012 14:33:38 -0400 Subject: [PATCH] Rename `getValue` to `result`. --- index.html | 10 +++++----- test/utility.js | 12 ++++++------ underscore.js | 2 +- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/index.html b/index.html index c6818b7a7..f2a00cae3 100644 --- a/index.html +++ b/index.html @@ -245,7 +245,7 @@
  • - mixin
  • - uniqueId
  • - escape
  • -
  • - getValue
  • +
  • - result
  • - template
  • @@ -1310,16 +1310,16 @@ _.uniqueId('contact_'); _.escape('Curly, Larry & Moe'); => "Curly, Larry & Moe" -

    - 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;