I have a method inside a class that uses lodash's get and looks like this:
get(path, defaultValue = '–') {
const result = _.get(this, path, defaultValue);
return result;
}
Assuming that result is a string, is there a chance to add a prototype method isDefault? I've tried implementation below and it does not work:
get(path, defaultValue = '–') {
const result = _.get(this, path, defaultValue);
result.isDefault = () => result === defaultValue;
return result;
}
I know that I could just wrap the result in a class and define the method there, but I also want to just write console.log(result) to get a string printed on my screen.
result.prototype.isDefaultgives an errorFunctionobjects (and classes) have a.prototypeproperty.