developit / decko

:dash: The 3 most useful ES7 decorators: bind, debounce and memoize
https://developit.github.io/decko/
MIT License
1.03k stars 36 forks source link

Fix bind example test #4

Closed bryanjenningz closed 7 years ago

bryanjenningz commented 7 years ago

The current bind example test will succeed even without using @bind. This is because of the way that e.foo is being called in the example test. When it is called like e.foo(), the e is to the left of the dot, so e is passed in as the this argument to the foo function. So the test assert.equal(e.foo(), e) will be true regardless of whether @bind is used. To fix this, we can change the test to assert.equal(e.call(null), e) to explicitly pass in null as the this argument for foo using Function.prototype.call.

developit commented 7 years ago

Works for me! Easier than explaining the assignment problem.