https://underscorejs.org/underscore-min.js
and getting a 404. Not sure if that's something controlled by these maintainers
underscore.js
alias in git and on the website. That means that cnn.com/activate is un-broken for now, though I find it worrying that they haven't already switched to a CDN url.
as i can see _.result() does not support invoke arguments and it makes it useless with arrow functions.
const obj = {
propertyA: 'foo',
propertyB: obj => obj.propertyA,
propertyC() { return this.propertyA; }
}
_.result(obj,'propertyB'); // will throw
_.result(obj,'propertyC');
so, i am interesting how you solve that in your projects? do you just do not use arrow functions or you implement some other _.result
able to handle this ?
_.powerResult(obj, property, [invokeArgs], defaultValue):
_.powerResult(obj, property, defaultValue) = obj.property.call(obj, obj)
_.powerResult(obj, property, nonArrayInvokeArgument, defaultValue) = obj.property.call(obj, nonArrayInvokeArgument)
_.powerResult(obj, property, [arg1, arg2], defaultValue) = obj.property.apply(obj, [arg1, arg2])
when calling result with 2 or 3 params - behave mostly as usual except passing obj as first argument
when calling result with 4 params - take third param as invoke argument/arguments.
But i don't use _.result in my applications because i dislike that idea of invoking property of object and because of current limitation.
It seems that this method was invented for some certain case.
Personally i prefer to have invokeValue
function invokeValue(value, invokeArgs, invokeContext) {
...
}
_.powerResult(obj, property, options)
{
defaultValue: any, optional,
invokeArgs: any, optional // array or single value shoud be handled separated
invokeContext: any, optional
}
powerResult(obj, property, defaultValue)
&& powerResult(obj, property, options)
:(
powerResult(obj, options, property)
_.result
was conceived for, I think, is in OOP situations where a value may be obtained from an instance either through a fixed property value or a zero-argument method. It is used a lot under the hood of Backbone, for example for Model#urlRoot
/Model#urlRoot()
. I do personally use it occasionally for this purpose, even outside of Backbone.
_.result
should support passing arguments. It could be extended to accept a fourth argument.
view.extend({
childView: MyOtherView, // ok
childView() { // this is OK too
if (condition1) {
return View1;
} else {
return View2;
}
}
})
basicaly for such cases