showing alternatives would be cool for beginners, like
add5 = x => add(5, x) which is far less confusing,
and even better
add = x => y => x + y;
add5 = add(5)
How’s it going, I'm a Adam, a Full-Stack Engineer, actively searching for work. I'm all about JavaScript. And Frontend but don't let that fool you - I've also got some serious Backend skills.
Location
City of Bath, UK 🇬🇧
Education
10 plus years* active enterprise development experience and a Fine art degree 🎨
I 100% agree it is not idiomatic however that is not the point, The point is, I did not know about this for many years and I probably would have went down the functional path sooner had I known about this, I would then look into currying as you say. If ever there was an edge case where currying could not be used and an arg needed to be passed, this might come in handy. (alot of my posts talk about exotic less than idiomatic things, see operator overloading as an example)
I do prefer the first option you mention. Now, I don't think a bound function is exotic anymore. When the class keyword was first introduced in ES6 a lot of people found that .bind helped them keep the methods behavior consistent. Maybe they don't know they can use it to achieve partial application but they know .bind exists.
I actually wrote something about partial application a while ago, here is the link.
well, yes but I wouldn't advise doing it this way, a bound function is quite exotic: ecma-international.org/ecma-262/#s...
showing alternatives would be cool for beginners, like
add5 = x => add(5, x) which is far less confusing,
and even better
add = x => y => x + y;
add5 = add(5)
I 100% agree it is not idiomatic however that is not the point, The point is, I did not know about this for many years and I probably would have went down the functional path sooner had I known about this, I would then look into currying as you say. If ever there was an edge case where currying could not be used and an arg needed to be passed, this might come in handy. (alot of my posts talk about exotic less than idiomatic things, see operator overloading as an example)
I have added a disclaimer.
I do prefer the first option you mention. Now, I don't think a bound function is exotic anymore. When the
class
keyword was first introduced in ES6 a lot of people found that.bind
helped them keep the methods behavior consistent. Maybe they don't know they can use it to achieve partial application but they know.bind
exists.I actually wrote something about partial application a while ago, here is the link.
exotic as in: ecma-international.org/ecma-262/#s...
Today I learned.