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.

Request: Apply arguments on .bind()

See original GitHub issue

Allow applying arguments on .bind().

function one(foo) {
  console.log('Got foo:', foo); // should print 'go'
  console.log('Got context:', this.a); // prints 'lol'
}

Promise.resolve()
  .bind({a: 'lol'}, 'go')
  .then(one);

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:24 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
thanpolascommented, Aug 27, 2014

Yea, I can’t disagree with you @phpnode, and that’s a good workaround… My only problem is that I always work with constructors and prototypes and the context needs to be there as is, intact (it can’t be a new Object) … or it’d be a new idiom of the type:

var context = {
  self: this,
  req: req,
  res: res,
};

This discussion wouldn’t happen if V8’s bind() implementation wasn’t slow enough to justify it.

0reactions
SudoPlzcommented, Oct 24, 2016

I know I’m necromancing this feature request, but I’d love to see the initial suggestion implemented as well!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Use the Call, Apply, and Bind Functions in JavaScript
In this article, I am going to explain how to use call, apply, and bind in JavaScript with simple examples.
Read more >
Javascript: call(), apply() and bind() - Medium
When we use the bind() method: the JS engine is creating a new pokemonName instance and binding pokemon as its this variable. It...
Read more >
Learn & Solve : call(), apply() and bind() methods in JavaScript
The bind() method creates a new function where “this” refers to the parameter in the parenthesis in the above case “car”. This way...
Read more >
Function.prototype.bind() - JavaScript - MDN Web Docs - Mozilla
The bound function will store the parameters passed — which include the value of this and the first few arguments — as its...
Read more >
Javascript call() & apply() vs bind()? - Stack Overflow
call and apply call a function while bind creates a function. Though with call() you pass arguments individually and apply() as an argument...
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