140

As you know, there is a proposal for a shortcut for .bind() function, so you can write:

::this.handleStuff

and it will work like that in es5:

this.handleStuff.bind(this)

My question is: will it be possible to pass arguments this way?

I mean a way of writing this with the aforementioned shortcut:

this.handleStuff.bind(this, 'stuff')

It's a pretty common pattern in React, so it would be nice to shorten it a little.

2
  • 3
    Are you talking about partial application? Commented Jul 4, 2015 at 13:29
  • Seem like a good idea for yet another spec proposal. Commented Nov 11, 2017 at 6:03

1 Answer 1

165

No. The bind operator (spec proposal) comes in two flavours:

  • Method extraction

    ::obj.method     ≡ obj.method.bind(obj)
    
  • "virtual method" calls

    obj::function    ≡ function.bind(obj)
    obj::function(…) ≡ function.call(obj, …)
    

Neither of them feature partial application. For what you want, you should use an arrow function:

(...args) => this.handleStuff('stuff', ...args) ≡ this.handleStuff.bind(this, 'stuff')
Sign up to request clarification or add additional context in comments.

1 Comment

(There was some discussion about supporting partial application)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.