Pass argumets to lodash _.result

I looked at the source code of lodash _.result function and there is no support for this. You can implement your own function for this and extend lodash with it using _.mixin.

function myResult(object, path, defaultValue) {
    result = object == null ? undefined : object[path];
    if (result === undefined) {
        result = defaultValue;
    }
    return _.isFunction(result) 
        ? result.apply(object, Array.prototype.slice.call( arguments, 2 )) 
        : result;
}

// add our function to lodash
_.mixin({ myResult: myResult})


_.myResult(object, 'cheese');
// "crumpets"

_.myResult(object, 'stuff', true);
// "nonsense"

_.myResult(object, 'stuff');
// "balderdash"