It wouldn’t in this case, as the function tested would retain its scope. It is functionally the same if you intent to bind the function to itself. In fact bind returns a new function (so you get 2 functions here as well), which is good to remember if using it with e.g. React event handlers (referential equality changes) 😊
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Another, maybe more intuitive way to do this in ES2016+ is to pass a lambda function calling the function that should throw. By your example:
assert.throws(() => foo('bar'), "Expected error message");
Gives you the same result :) Anyway, nice post! I know this behavior tripped up many people on my team.
Absolutely! I think even a simple anonymous function would work, but in that case the scope may bite you 😂
It wouldn’t in this case, as the function tested would retain its scope. It is functionally the same if you intent to bind the function to itself. In fact bind returns a new function (so you get 2 functions here as well), which is good to remember if using it with e.g. React event handlers (referential equality changes) 😊