max-mapper / max-mapper/callback-hell
Callback binding
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 858
- Forks
- 101
- PR merge metrics
- No merged PRs in 30d
Description
Maybe it would be useful to mention callback binding, I know that personally was confusing for me in the beginning. For instance, you might expect this to work:
Something.prototype.foo = function (cb) {
someOtherObj.bar(function (err, res) {
cb(null, this.value)
})
}
But actually it will not work since the innermost callback is called from the context of someOtherObj, and this doesn't resolve to the Something instance (so this.value end up being something else).
The solutions are foo(function () { this.value... }.bind(this)), var self = this; foo(function () { self.value... }), or maybe ES6 arrow functions (since they take their context from wherever they were created), () => { this.value... }.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file, test, or documentation entry point is named; first locate the section covering JavaScript callbacks and this binding. Add a clear example of the confusing context and the suggested binding alternatives, then verify the documentation renders correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100