This method is like `get` except that if the resolved value is a function it's invoked with the `this` binding of its parent object and its result is returned.
const object = { 'a': [{ 'b': { 'c1': 3, 'c2': constant(4) } }] }
result(object, 'a[0].b.c1')
// => 3
result(object, 'a[0].b.c2')
// => 4
result(object, 'a[0].b.c3', 'default')
// => 'default'
result(object, 'a[0].b.c3', constant('default'))
// => 'default'
Name | Type | Attribute | Description |
---|---|---|---|
object | The object to query. | ||
path | The path of the property to resolve. | ||
defaultValue | The value returned for `undefined` resolved values. |
*
{ "comment": "/**\r\n * This method is like `get` except that if the resolved value is a\r\n * function it's invoked with the `this` binding of its parent object and\r\n * its result is returned.\r\n *\r\n * @since 0.1.0\r\n * @category Object\r\n * @param {Object} object The object to query.\r\n * @param {Array|string} path The path of the property to resolve.\r\n * @param {*} [defaultValue] The value returned for `undefined` resolved values.\r\n * @returns {*} Returns the resolved value.\r\n * @example\r\n *\r\n * const object = { 'a': [{ 'b': { 'c1': 3, 'c2': constant(4) } }] }\r\n *\r\n * result(object, 'a[0].b.c1')\r\n * // => 3\r\n *\r\n * result(object, 'a[0].b.c2')\r\n * // => 4\r\n *\r\n * result(object, 'a[0].b.c3', 'default')\r\n * // => 'default'\r\n *\r\n * result(object, 'a[0].b.c3', constant('default'))\r\n * // => 'default'\r\n */", "meta": { "range": [ 886, 1417 ], "filename": "result.js", "lineno": 31, "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo", "code": { "id": "astnode100007819", "name": "result", "type": "FunctionDeclaration", "paramnames": [ "object", "path", "defaultValue" ] }, "vars": { "path": "result~path", "index": "result~index", "length": "result~length", "object": "result~object", "value": "result~value" } }, "description": "This method is like `get` except that if the resolved value is a\rfunction it's invoked with the `this` binding of its parent object and\rits result is returned.", "since": "0.1.0", "tags": [ { "originalTitle": "category", "title": "category", "text": "Object", "value": "Object" } ], "params": [ { "type": { "names": [ "Object" ] }, "description": "The object to query.", "name": "object" }, { "type": { "names": [ "Array", "string" ] }, "description": "The path of the property to resolve.", "name": "path" }, { "type": { "names": [ "*" ] }, "optional": true, "description": "The value returned for `undefined` resolved values.", "name": "defaultValue" } ], "returns": [ { "type": { "names": [ "*" ] }, "description": "Returns the resolved value." } ], "examples": [ "const object = { 'a': [{ 'b': { 'c1': 3, 'c2': constant(4) } }] }\r\rresult(object, 'a[0].b.c1')\r// => 3\r\rresult(object, 'a[0].b.c2')\r// => 4\r\rresult(object, 'a[0].b.c3', 'default')\r// => 'default'\r\rresult(object, 'a[0].b.c3', constant('default'))\r// => 'default'" ], "name": "result", "longname": "result", "kind": "function", "scope": "global", "___id": "T000002R000715", "___s": true, "filepath": "result.js" }