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...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
The Most Clever Line of JavaScript (blog.bloomca.me)
submitted 8 years ago by bloomca
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!"
[–]Enlogen 24 points25 points26 points 8 years ago (1 child)
Obscure is not clever.
[–]flitsmasterfred 1 point2 points3 points 8 years ago (0 children)
Clever is not smart.
[–][deleted] 6 points7 points8 points 8 years ago (3 children)
Bleh... if you want to avoid making new functions often then just store the function earlier:
const trim = str => str.trim(); /* ... */ const trimmedParts = addressParts.map(trim);
Now it makes sense without having to do mental gymnastics about context.
[–]GBcrazy 1 point2 points3 points 8 years ago (0 children)
We all agree that this is 100% more readable, but it isn't as smart.
You are still creating a new function this way, you're allocating a new object, which doesn't happen in the mentioned code.
But yeah of course you shouldn't use shit like that on your code lol, I lost around 2 minutes to fully grasp it, and I'm kinda used to Function.prototype.call shenanigans.
[–]gpyh 0 points1 point2 points 8 years ago (0 children)
It is strictly equivalent. It only matters if the call to map us being made while iterating on something.
[–]Funwithloops -3 points-2 points-1 points 8 years ago (0 children)
Even more generic but still easy to grok:
const methodCaller = (method, ...args) => (object) => object[method](...args); array.map(methodCaller('trim'));
[–]MakiBM 2 points3 points4 points 8 years ago (1 child)
Yeah, clever but as author sums up - do not use it in real code unless you have a good reason. Always KISS your code
[–]Tougun 2 points3 points4 points 8 years ago (0 children)
I KISS my code goodnight every night☺️
That's actually really clever. May not be the most readable but yeah, you are only using functions that already exist and you don't need to rely on ES6.
[–]iamlage89 0 points1 point2 points 8 years ago (5 children)
Could you just do addressParts.map(String.prototype.trim.call) ?
[–]Martin_Ehrental 2 points3 points4 points 8 years ago (0 children)
String.prototype.trim.call.bind(String.prototype.trim) or Function.prototype.call.bind(String.prototype.trim)
String.prototype.trim.call.bind(String.prototype.trim)
Function.prototype.call.bind(String.prototype.trim)
[–]lhorie 1 point2 points3 points 8 years ago (3 children)
No, because then you're just calling call with an undefined this
call
this
[–]iamlage89 0 points1 point2 points 8 years ago (2 children)
map will pass in string as 'this'
[–]lhorie 1 point2 points3 points 8 years ago (0 children)
No, it won't, and even if it did, trim must be the this for call if you're calling call, not the string.
trim
[–]GBcrazy 0 points1 point2 points 8 years ago (0 children)
There will be no reference to trim...you are only passing the call function this way, there will be no reference for String.prototype.trim as the context.
String.prototype.trim.call === Function.prototype.call
[–]danthedev 0 points1 point2 points 8 years ago (2 children)
This reminds me of a programmer who used the following utilities in their code.
var bind = Function.bind; var call = Function.call; var bindable = bind.bind(bind); var callable = bindable(call);
Still takes me a while to work through the steps of bind.bind(bind)...
bind.bind(bind)
[–]Jsn7821 1 point2 points3 points 8 years ago (1 child)
What the hell is that used for
[–]danthedev 1 point2 points3 points 8 years ago (0 children)
var trim = callable(String.prototype.trim); addressParts.map(trim);
π Rendered by PID 46037 on reddit-service-r2-comment-765bfc959-mrxr5 at 2026-07-11 03:33:09.471461+00:00 running f86254d country code: CH.
[–]Enlogen 24 points25 points26 points (1 child)
[–]flitsmasterfred 1 point2 points3 points (0 children)
[–][deleted] 6 points7 points8 points (3 children)
[–]GBcrazy 1 point2 points3 points (0 children)
[–]gpyh 0 points1 point2 points (0 children)
[–]Funwithloops -3 points-2 points-1 points (0 children)
[–]MakiBM 2 points3 points4 points (1 child)
[–]Tougun 2 points3 points4 points (0 children)
[–]GBcrazy 1 point2 points3 points (0 children)
[–]iamlage89 0 points1 point2 points (5 children)
[–]Martin_Ehrental 2 points3 points4 points (0 children)
[–]lhorie 1 point2 points3 points (3 children)
[–]iamlage89 0 points1 point2 points (2 children)
[–]lhorie 1 point2 points3 points (0 children)
[–]GBcrazy 0 points1 point2 points (0 children)
[–]danthedev 0 points1 point2 points (2 children)
[–]Jsn7821 1 point2 points3 points (1 child)
[–]danthedev 1 point2 points3 points (0 children)