Merge pull request #512 from braddunbar/getvalue

Add utility function `result`.
This commit is contained in:
brad dunbar
2012-03-19 11:46:26 -07:00
3 changed files with 120 additions and 91 deletions

View File

@@ -873,6 +873,13 @@
return (''+string).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/\//g,'&#x2F;');
};
// Get a value from an object as a property or as a function.
_.result = function(object, property) {
if (object == null) return null;
var value = object[property];
return _.isFunction(value) ? value() : value;
};
// Add your own custom functions to the Underscore object, ensuring that
// they're correctly added to the OOP wrapper as well.
_.mixin = function(obj) {