00001 var castPath = require('./_castPath'),
00002 isFunction = require('./isFunction'),
00003 toKey = require('./_toKey');
00004
00034 function result(object, path, defaultValue) {
00035 path = castPath(path, object);
00036
00037 var index = -1,
00038 length = path.length;
00039
00040
00041 if (!length) {
00042 length = 1;
00043 object = undefined;
00044 }
00045 while (++index < length) {
00046 var value = object == null ? undefined : object[toKey(path[index])];
00047 if (value === undefined) {
00048 index = length;
00049 value = defaultValue;
00050 }
00051 object = isFunction(value) ? value.call(object) : value;
00052 }
00053 return object;
00054 }
00055
00056 module.exports = result;