Skip to content

Fix bind example test#4

Merged
developit merged 1 commit intodevelopit:masterfrom
bryanjenningz:patch-1
Feb 1, 2017
Merged

Fix bind example test#4
developit merged 1 commit intodevelopit:masterfrom
bryanjenningz:patch-1

Conversation

@bryanjenningz
Copy link
Copy Markdown
Contributor

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.

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
Copy link
Copy Markdown
Owner

Works for me! Easier than explaining the assignment problem.

@developit developit merged commit 6a83b0f into developit:master Feb 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants