added _.result definition

This commit is contained in:
Brian Zengel
2013-10-20 18:39:40 -04:00
parent 497c93e81a
commit 5038619a71
2 changed files with 19 additions and 9 deletions
+10
View File
@@ -732,6 +732,16 @@ result = <number>_.random(5, true);
result = <number>_.random(1.2, 5.2);
result = <number>_.random(0, 5, true);
var object = {
'cheese': 'crumpets',
'stuff': function() {
return 'nonsense';
}
};
result = <any>_.result(object, 'cheese');
result = <any>_.result(object, 'stuff');
//////////////////////////////////////////////////////////////////////////////////////////////////
var iceCream = { flavor: "chocolate" };
+9 -9
View File
@@ -2762,7 +2762,15 @@ declare module _ {
**/
export function random(min: number, max: number, floating?: boolean): number;
/**
* Resolves the value of property on object. If property is a function it will be invoked with
* the this binding of object and its result returned, else the property value is returned. If
* object is falsey then undefined is returned.
* @param object The object to inspect.
* @param property The property to get the value of.
* @return The resolved value.
**/
export function result(object: any, property: string): any;
@@ -2795,14 +2803,6 @@ declare module _ {
/**
* If the value of the named property is a function then invoke it; otherwise, return it.
* @param object Object to maybe invoke function `property` on.
* @param property The function by name to invoke on `object`.
* @return The result of invoking the function `property` on `object.
**/
export function result(object: any, property: string): any;
/**
* Compiles JavaScript templates into functions that can be evaluated for rendering. Useful
* for rendering complicated bits of HTML from JSON data sources. Template functions can both