mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-08 02:17:48 +00:00
Rename getValue to result.
This commit is contained in:
10
index.html
10
index.html
@@ -245,7 +245,7 @@
|
|||||||
<li>- <a href="#mixin">mixin</a></li>
|
<li>- <a href="#mixin">mixin</a></li>
|
||||||
<li>- <a href="#uniqueId">uniqueId</a></li>
|
<li>- <a href="#uniqueId">uniqueId</a></li>
|
||||||
<li>- <a href="#escape">escape</a></li>
|
<li>- <a href="#escape">escape</a></li>
|
||||||
<li>- <a href="#getValue">getValue</a></li>
|
<li>- <a href="#result">result</a></li>
|
||||||
<li>- <a href="#template">template</a></li>
|
<li>- <a href="#template">template</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@@ -1310,16 +1310,16 @@ _.uniqueId('contact_');
|
|||||||
_.escape('Curly, Larry & Moe');
|
_.escape('Curly, Larry & Moe');
|
||||||
=> "Curly, Larry &amp; Moe"</pre>
|
=> "Curly, Larry &amp; Moe"</pre>
|
||||||
|
|
||||||
<p id="getValue">
|
<p id="result">
|
||||||
<b class="header">getValue</b><code>_.getValue(object, property)</code>
|
<b class="header">result</b><code>_.result(object, property)</code>
|
||||||
<br />
|
<br />
|
||||||
Returns a value from an object as a property or as a function.
|
Returns a value from an object as a property or as a function.
|
||||||
</p>
|
</p>
|
||||||
<pre>
|
<pre>
|
||||||
var object = {cheese: 'crumpets', stuff: function(){ return 'nonsense'; }};
|
var object = {cheese: 'crumpets', stuff: function(){ return 'nonsense'; }};
|
||||||
_.getValue(object, 'cheese');
|
_.result(object, 'cheese');
|
||||||
=> "crumpets"
|
=> "crumpets"
|
||||||
_.getValue(object, 'stuff');
|
_.result(object, 'stuff');
|
||||||
=> "nonsense"</pre>
|
=> "nonsense"</pre>
|
||||||
|
|
||||||
<p id="template">
|
<p id="template">
|
||||||
|
|||||||
@@ -165,13 +165,13 @@ $(document).ready(function() {
|
|||||||
strictEqual(tmpl(), '<p>\u2028\u2028\u2029\u2029</p>');
|
strictEqual(tmpl(), '<p>\u2028\u2028\u2029\u2029</p>');
|
||||||
});
|
});
|
||||||
|
|
||||||
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'; }};
|
var obj = {w: '', x: 'x', y: function(){ return 'y'; }};
|
||||||
strictEqual(_.getValue(obj, 'w'), '');
|
strictEqual(_.result(obj, 'w'), '');
|
||||||
strictEqual(_.getValue(obj, 'x'), 'x');
|
strictEqual(_.result(obj, 'x'), 'x');
|
||||||
strictEqual(_.getValue(obj, 'y'), 'y');
|
strictEqual(_.result(obj, 'y'), 'y');
|
||||||
strictEqual(_.getValue(obj, 'z'), undefined);
|
strictEqual(_.result(obj, 'z'), undefined);
|
||||||
strictEqual(_.getValue(null, 'x'), null);
|
strictEqual(_.result(null, 'x'), null);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -874,7 +874,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Get a value from an object as a property or as a function.
|
// 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;
|
if (object == null) return null;
|
||||||
var value = object[prop];
|
var value = object[prop];
|
||||||
return _.isFunction(value) ? value() : value;
|
return _.isFunction(value) ? value() : value;
|
||||||
|
|||||||
Reference in New Issue
Block a user