question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Methods for keeping this

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
sindresorhuscommented, May 9, 2016

Yeah, not worth saving just a few characters. Using bind is a lot clearer too.

0reactions
LinusUcommented, May 9, 2016

I’ve rarely encountered the need to use bind though. Most API’s in the Node.js world are luckily not using this.

True, I guess that this is good enough for now 👍 thanks for the discussion

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found