lodash: changed _.get() (added to the chainable wrapper)

This commit is contained in:
Ilya Mochalov
2015-07-21 15:47:02 +05:00
parent 8f51d25ad3
commit f695ec7d24
2 changed files with 25 additions and 3 deletions
+14 -1
View File
@@ -936,7 +936,20 @@ result = <string[]>_.methods(_);
result = <_.LoDashArrayWrapper<string>>_(_).functions();
result = <_.LoDashArrayWrapper<string>>_(_).methods();
result = <number>_.get({ 'a': 1, 'b': 2, 'c': 3 }, 'b');
// _.get
result = <number>_.get<number>({ 'a': [{ 'b': { 'c': 3 } }] }, 'a[0].b.c');
// → 3
result = <number>_.get<number>({ 'a': [{ 'b': { 'c': 3 } }] }, ['a', '0', 'b', 'c']);
// → 3
result = <string>_.get<string>({ 'a': [{ 'b': { 'c': 3 } }] }, 'a.b.c', 'default');
// → 'default'
result = <number>_({ 'a': [{ 'b': { 'c': 3 } }] }).get<number>('a[0].b.c');
// → 3
result = <number>_({ 'a': [{ 'b': { 'c': 3 } }] }).get<number>(['a', '0', 'b', 'c']);
// → 3
result = <string>_({ 'a': [{ 'b': { 'c': 3 } }] }).get<string>('a.b.c', 'default');
// → 'default'
result = <boolean>_.has({ 'a': 1, 'b': 2, 'c': 3 }, 'b');
+11 -2
View File
@@ -5756,12 +5756,21 @@ declare module _ {
* @param defaultValue The value returned if the resolved value is undefined.
* @return Returns the resolved value.
**/
get<T>(object : Object,
path:string|string[],
get<T>(object: Object,
path: string|string[],
defaultValue?:T
): T;
}
interface LoDashObjectWrapper<T> {
/**
* @see _.get
**/
get<TResult>(path: string|string[],
defaultValue?: TResult
): TResult;
}
//_.has
interface LoDashStatic {
/**