I've had a look at the lodash filter documentation and it's unclear whether the third parameter is a context.
I'm using a cytoscape plugin (dagre) and it seems to pass this
as a 3 argument. When I pause the execution before the filter method is called, this
is defined. But within the call this
is undefined.
I had a look at the underscore filter documentation and it seems to take a third argument as a context. So I'm kinda guessing that the plugin originally used underscore then maybe changed to lodash. The project I'm working on is using lodash.
I can't understand why this
is null at that point in my could. It could be project specific but I just want to be clear on the third parameter of lodash's filter.
Is the definition of lodash's filter exactly the same as underscore's filter? It does not seem so from the documentation.
Well you can always define your own context using Function.prototype.bind
.
_.filter([…],
function (o) {
console.log(this.id); //100
//than return something based on o
return o.active
}.bind({id: 100})
);
Doc on mdn
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With