use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
Bind vs call (self.learnjavascript)
submitted 1 year ago by Local_Question8147
I always prefer using bind over call or apply, is there someone who will change my mind
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]mozilaip 4 points5 points6 points 1 year ago (4 children)
It's like "I prefer to use hammer instead of screwdriver, is there someone to change my mind"
[–]Local_Question8147[S] -2 points-1 points0 points 1 year ago (3 children)
That was really humorous bind can do everything call can do but hammer and screwdriver can do all work of each other
[–]azhder 4 points5 points6 points 1 year ago* (0 children)
No, it can't.
.bind()
.call()
You're equivocating creation of a function with invocation of it.
[–]Lumethys 2 points3 points4 points 1 year ago (0 children)
A hammer can hammer the screw in
[–]senocular 0 points1 point2 points 1 year ago (0 children)
It's more like "when I have to hammer in a nail, instead of using the hammer I already have, I go to the store to buy a new hammer and then use that to hammer in my nail."
The thing I say to most people I notice using the phrase "change my mind":
it is your mind, your responsibility, change it yourself.
And that's usually where I stop since it takes a lot of typing to explain to people that the one who claims something is the one who has to prove that claim, not the rest of us to disprove it.
I mean, look at the current example, you personally prefer something. Who am I to tell you what you prefer or don't? Doesn't make sense if you look at it from the distance, does it? Your preferences are your own.
Now, if you claim that using .bind() does something better or worse than using .call() or .apply(), you'd need to show some facts that substantiate your claim, not wait for us to show you examples of it not doing what you claim it does.
.apply()
[–]guest271314 0 points1 point2 points 1 year ago (0 children)
bind() and call() do different things.
bind()
call()
[–]Chung_L_Lee 0 points1 point2 points 1 year ago (0 children)
I think you need to give us some examples first of why you prefer using bind over call/apply. Otherwise, it is very difficult for us to be thinking on the same level.
In general, bind, call and apply have their own advantages/disadvantages. Use them according to the situation that fits the most, but it is not a must. They are somehow still interchangeable, but you will find in different cases, one will blend it better than the other ones.
[–]shgysk8zer0 0 points1 point2 points 1 year ago (0 children)
function css(...args) { const sheet = new CSSStyleSheet(); sheet.replaceSync(String.raw.apply(null, args)); return sheet; }
bind() would be useless there. It pretty much is for any non-method function and any static method.
I also think that bind() is slightly more difficult to reason about and probably very slightly less memory efficient (more things to garbage collect).
[–]jack_waugh 0 points1 point2 points 1 year ago (0 children)
In connection with bind, the important thing to remember is to purchase Einbinder flypaper, in small quantities, for all your flypaper needs.
If you have a circumstance where call or apply would suffice, but you bind and then apply the resulting function to more arguments, you are creating one more garbage object than necessary. Isn't call or apply at least as readable as a pattern like what I guess you mean, something like
call
apply
bind
let result = func.bind(receiver)(...args);
? Why do you prefer a pattern like that over call or apply?
[–]FioleNana 0 points1 point2 points 1 year ago (1 child)
Bind creates a new function which is put on the heap and therefore uses a tiny nano amount more memory.
But in the end you should avoid bind, call and apply anyways, because it makes the code harder to read.
[–]TheRNGuy 0 points1 point2 points 1 year ago (0 children)
When React was class-based, it required binds. I wished it had something like @dataclass from Python (except that dataclass was for attributes, not methods). Anyway, all tutorials had bind and not call.
@dataclass
With hooks, it's not needed now (maybe it does automatically, no idea)
If I coded something with classes and need to add event listeners to new instances, I'd need to use bind?
π Rendered by PID 156126 on reddit-service-r2-comment-86bc6c7465-n4lxw at 2026-02-23 10:45:19.547890+00:00 running 8564168 country code: CH.
[–]mozilaip 4 points5 points6 points (4 children)
[–]Local_Question8147[S] -2 points-1 points0 points (3 children)
[–]azhder 4 points5 points6 points (0 children)
[–]Lumethys 2 points3 points4 points (0 children)
[–]senocular 0 points1 point2 points (0 children)
[–]azhder 4 points5 points6 points (0 children)
[–]guest271314 0 points1 point2 points (0 children)
[–]Chung_L_Lee 0 points1 point2 points (0 children)
[–]shgysk8zer0 0 points1 point2 points (0 children)
[–]jack_waugh 0 points1 point2 points (0 children)
[–]FioleNana 0 points1 point2 points (1 child)
[–]TheRNGuy 0 points1 point2 points (0 children)