Methods for keeping this
See original GitHub issueI find that I quite often need to preserve this
when calling functions that takes callbacks. I have used something similar to the code below, but I would like to hear what you think of the matter.
Is there an easy way to support this use case?
function promise (obj, fn) {
return pify(obj[fn]).bind(obj)
}
await promise(linus, 'walk')(100, 'miles')
console.log('Linus walked 100 miles')
// vs.
linus.walk(100, 'miles', () => console.log('Linus walked 100 miles'))
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Follow These 8 Inventory Control Methods to Keep Your Store ...
This inventory management technique helps you to prioritize products, categorizing each item under one of the following: A (high-value products, ...
Read more >Methods for Keeping the Design Pipeline Full Over the Winter
However, keeping your design pipeline full over the winter season is still possible. While it was more of a struggle to keep their...
Read more >Ten strategies for keeping children safe on the road
World Health Organization. (2015). Ten strategies for keeping children safe on the road.
Read more >5S Lean Methodology, Systems & Principles
Sort through materials, keeping only the essential items needed to complete tasks. (This action involves going through all the contents of a workspace...
Read more >Human Resources Techniques & Strategies for Keeping the ...
What are human resources techniques for keeping the best employees? Improve your hiring practices; Create a structured onboarding program; Provide a career ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yeah, not worth saving just a few characters. Using
bind
is a lot clearer too.True, I guess that this is good enough for now 👍 thanks for the discussion