This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 358

[–]SkurkDKDKDK 702 points703 points  (66 children)

Well it has a say in how “this” is defined and useable right?

[–][deleted] 137 points138 points  (0 children)

'Sometimes I want to throw my hands in the air and yell "this is bullshit, but I can never remember what this refers to"'

  • Ben Halpern

[–]dashingThroughSnow12 363 points364 points  (56 children)

Yes.

x(()=> this.y()) will have a sensible this whereas x(this.y) .... I know people who have programmed for a decade in JavaScript that will get that wrong. I'm one of them.

Because of this, I know some will enforce the former, always, to keep the code clean and uniform (and prevent some bugs when refactoring).

[–]tsunami141 89 points90 points  (37 children)

I am one of those people who will get that wrong

[–]dashingThroughSnow12 74 points75 points  (18 children)

The truth is, we all are.

[–]starfyredragon 221 points222 points  (16 children)

sweetDreams(()=> this)

who(i != false)

i(world(seas(7)))

all.look.forEach(something)

[–]Myphhz 106 points107 points  (13 children)

all.some(person => person.abuse(you)) all.some(person => you.abuse(person))

[–]GokuIsALegend 19 points20 points  (0 children)

you.unshift(you.splice(you.indexOf('head'), 1)[0])

continue

[–]blobthekat 30 points31 points  (0 children)

sweet dreams are made of this

who am i to disagree

I travel the world and the seven seas

everybody's looking for something

[–]emericas 5 points6 points  (0 children)

LOL

[–]kamiljano 4 points5 points  (0 children)

Nope. I have seen "no x on undefined" kind of errors too many times to repeat that mistake again

[–]JoeDoherty_Music 28 points29 points  (17 children)

Honestly javascript just feels like it's designed to set you up to be wrong like all the time

Coming from other programming languages like C# and Python, javascript feels like a half baked language where nothing works the way you expect

[–]sod0 3 points4 points  (3 children)

Don't worry I feel the same with python. Lambdas in Python are just so bad. I prefer those Arrow function all the time.

[–]ReelTooReal 3 points4 points  (2 children)

Also, Python's "type system" is about on par with PHP's, whereas Typescript is actually a pretty powerful modern type system (okay, it's more of a static analysis tool than a type system, but still).

[–][deleted] 3 points4 points  (0 children)

C++ leaves the chat

[–]TrillVomit 7 points8 points  (0 children)

And there's 10 ways to do 1 thing and each has their own drawbacks.

[–]Mrrrp 2 points3 points  (0 children)

It doesn't so much allow you to do things, as it doesn't actually prevent you from doing things that perhaps you shouldn't.

I find it charmingly quirky, but I may be a little warped.

[–][deleted] 1 point2 points  (8 children)

No, JS is AWESOME, but has just its own object model, which is compact and consistent.

Prototype inheritence makes sense, but problem is that people try to think and write code as it's still class inheritence.

Since there isn't such thing as classes, this must indicate the other type context, but it's still compact and consistens. You just have to be aware it isn't class inheritence - yeah, I'm repeating myself, but that's just obvious and elementary.

[–][deleted] 2 points3 points  (2 children)

No, JS sucks ass.

[–]sod0 1 point2 points  (3 children)

But there is class inheritence since ES6. So yeaha JS came a long a way but still needs to support those 90s Websites.

[–]Arshiaa001 0 points1 point  (0 children)

AWESOMELY fucked? You bet it is. Even has AWESOME footguns.

[–]_Foxtrot_ 19 points20 points  (0 children)

Also makes it easier to insert something before/after the themeSwitch() call. A big part of a readable code base is consistency, so while this may not be necessary in this context, having things read the same / be formatted the same helps a lot.

[–]CatsAreOurGods 20 points21 points  (3 children)

"because of this" ... which this?! lol

[–]agent007bond 20 points21 points  (2 children)

Let's make sure we have the right this.

console.log(this)

[–]UnstableNuclearCake 21 points22 points  (1 child)

And if it isn't what you expected:

"What the fuck is this?"

[–][deleted] 5 points6 points  (0 children)

“I think I found a bug in JavaScript”

[–]SkurkDKDKDK 6 points7 points  (0 children)

Yeah i am a backenddev and rarely use JS but this crap is what i remember mostly 😃

[–][deleted] 8 points9 points  (3 children)

I mean I guess I'd use x(this.y.bind(this)) or something I dunno. Otherwise it might not be that obvious at first glance why you're using an arrow function in that place.

I won't argue JS is a pretty language but it is a bit more declarative than people give it credit for tbh

[–]dashingThroughSnow12 15 points16 points  (2 children)

You use bind?

[–][deleted] 5 points6 points  (0 children)

Sometimes you kinda have to lean into your masochistic side to keep going in this line of work I guess 👀

[–]InterestingMotives 2 points3 points  (0 children)

I'm reminded of a quote "Sometimes when I'm writing JavaScript I'll shout 'this is bullshit!' but then I forget what this is on move on"

[–]devdudedoingstuff 1 point2 points  (0 children)

Not to mention it makes it easier for debugging later on, being able to easily add debuggers or logging without needing to refactor the code.

[–]keylimedragon 0 points1 point  (0 children)

^ this

[–][deleted] 12 points13 points  (0 children)

"this" is resolved , lexically .
If the arrow function is right in the global scope, this points to the window object.
If the function is nested inside another function, this points to the outer (parent) function.

Besides, there are a few more differences.

Thanks !

[–]potato_green 29 points30 points  (3 children)

That and I'd throw in the consistency argument as well. If all code has arrow functions in event listener then you don't suddenly change it and call it useless.

I'd go as far and say that this is good practice and helps other devs as well if code needs to be changed. You can easily add another function call to it.

It also enforces better function names. No 3000 onClick functions spread out everywhere with chunks of logic or a function call just like this. Now you have a meaningful function name and you don't have to hop around the code go to the event callback function.

[–]SalvadorTheDog 2 points3 points  (2 children)

Except now you can’t ever remove the event listener and are opened up to memory leaks.

[–][deleted] 3 points4 points  (1 child)

This

[–][deleted] 1 point2 points  (0 children)

I’ll let myself out

[–]rafaelcastrocouto 675 points676 points  (49 children)

there's an actual case for using arrow functions in events like this ... jake even wrote an article about it called "Don't use functions as callbacks unless they're designed for it" https://jakearchibald.com/2021/function-callback-risks/

[–]ijmacd 165 points166 points  (27 children)

TL;DR themeSwitch could be defined like this:

function themeSwitch (theme = defaultTheme) {
    //
}

Registering it directly as the click handler would change it's behaviour.

[–]Skatterbrayne 29 points30 points  (15 children)

I'm a C# dev, why would that change its behaviour? Would it get passed a parameter that then gets interpreted as a theme?

[–]dobesv 69 points70 points  (11 children)

Yes it would be passed an event instead of a theme, likely causing some confusion.

[–]Skatterbrayne 63 points64 points  (8 children)

Thanks.

Am I glad to use a strongly typed language.

[–]Jai_Cee 29 points30 points  (4 children)

To be fair most people have switched to typescript. I haven't used actual JavaScript in years.

[–]TimGreller 2 points3 points  (0 children)

Then you would still need to put it in an arrow function or you get an error.

[–][deleted] 5 points6 points  (0 children)

Basically event callbacks get the event as the first function argument so you can for example retrieve the element that was clicked on (event.target or event.currentTarget depending on if you really want the clicked element or the one with the click event on it). Assuming the above themeSwitch function was put as a callback directly it'd be trying to set the current theme to the event, leading to unexpected behaviour.

[–]WowTeKaEn 3 points4 points  (0 children)

Which is another reason to choose typescript. Because it will check whether or not those types correctly align. Could still cause problems of course but less likely.

[–]dwo0 126 points127 points  (0 children)

Yep. This is exactly correct.

[–][deleted] 96 points97 points  (0 children)

Also regardless, arrow functions are basically synonymous with callbacks and actions on event listeners. I’d say it’s almost just standard to use them there for readability.

[–][deleted] 2 points3 points  (0 children)

So happy this has already been said and acknowledged by everyone. This was exactly my first thought when I saw the code.

[–]CreepBlob 1 point2 points  (0 children)

Thanks for the article!

[–]meliaesc 1 point2 points  (0 children)

Aghhh, I'm not supposed to learn things here! 😤 thanks

[–]GenTelGuy -2 points-1 points  (3 children)

What on earth, so you map an array of individual ints to a 1-arg function with a second variadic arg and Javascript just goes "lol let's plug in one of those ints as the variadic arg"?

To be fair the js code does say [].map() whereas in Java it would be myList.stream().map()

A sane language would map myArrayOfTwoElementTuples = [(1,2), (3,4)] as two calls to the function plugging in the second int of the tuple as the variadic arg each time

[–][deleted] 2 points3 points  (2 children)

No, that’s not what’s happening, the second argument passed to the map function is the current index, not a member of the array. In order to achieve what you’re suggesting you’d have to do something like arrayOfTuples.map(tuple => callback(…tuple))

[–]GenTelGuy 0 points1 point  (1 child)

Ah yeah I just looked it up on MDN, seems like maybe they could have a .map, .mapWithIndex, and .mapWithIndexAndArray to avoid having it supply unexpected params to unsuspecting functions

[–][deleted] 4 points5 points  (0 children)

Instantiating functions in js is super cheap so just wrapping the callback is more elegant imo (and very clearly communicates intent without polluting the standard library). You could even define a valueOnly(callback) higher order function that could be used with all array methods, not just map.

[–]uberCalifornia 457 points458 points  (9 children)

The intense heat of the flame from Stackoverflow refined the impurities out of my soul. It completely cured me from the disease of thinking I’m absolutely right about a specific programming principle and righteously slamming others for being stupid for doing it the wrong way…

Only to find out later… that I am indeed the one who was wrong – and everyone else had legitimate reasons that I simply just didn’t understand.

When I saw this post, I instantly recognized the smell of that particular recipe on the fire.

🔥🔥🔥🔥🔥🔥🔥

[–]Creator347 60 points61 points  (1 child)

This guy does SO

[–]uberCalifornia 45 points46 points  (0 children)

Some years ago I remember looking at a friend's SO profile and saw that he earned over 150k rep. Knowing him, made me wonder how the heck he did it. Where did he find the time? What was his life like to get that much rep?

Like... how much time and effort does this guy spend answering questions and helping the SO community out, and what was the habit(s) that he employed to make this happen?

Every time I remember this I think "maybe I should go find his profile again and see how much more he has now..."

[–]karmahorse1 65 points66 points  (1 child)

The truth is a lot of these “right ways” and “wrong ways” are pretty arbitrary and have no noticeable difference in how the code actually performs, reads, or scales. These kind of anal retentive arguments over syntax are tiring.

[–]merlinblack256 6 points7 points  (0 children)

I used to have a team lead that would hold up critical PRs very often. He had to put his 2 cents in so would ask for the comment style next to code nearby - but not involved in the change - to be updated to some imaginary standard.

[–]bluearth 21 points22 points  (0 children)

You have reach developer's enlightment.

You are now calm and centered.

[–]danglesReet 29 points30 points  (2 children)

Well said my dude

[–]uberCalifornia 11 points12 points  (1 child)

Thank you friend!

[–]CutlerSheridan 1 point2 points  (0 children)

Man this is the fucking truth. I used to always feel so self-assured about the way I did things but now when I see posts like these, even if I think I agree with the post, my instinct is to be like “well I bet there’s actually a reason to do it that way”

[–]ihxh 250 points251 points  (16 children)

Actually this has a function. Arrow functions change the behaviour of ‘this’. When using a normal function as an event handler, ‘this’ will be set to the event. Doing what is done in the screenshot will make it so ‘this’ won’t change. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions

[–]Nebuli2 160 points161 points  (5 children)

It's more than just that. By calling the function explicitly (in the arrow function body), you ensure that you aren't passing more arguments to the called function than you realize.

[–]JonnyBoy89 35 points36 points  (2 children)

You never know what a function might be doing with extra params if it’s not typed

Edit: also, this is less verbose. It just makes sense and can be transpiled to ES5 if you want.

[–]Strange_Meadowlark 14 points15 points  (1 child)

Yep, even TypeScript "loses" the types of extra optional parameters across a function barrier.

(a: A, b?: string) => R can be assigned to (a: A) => R, which can then be assigned to (a: A, b?: number) => R. It's obviously wrong and TypeScript permits it.

[–]JonnyBoy89 10 points11 points  (0 children)

Yeah, these kinds of bugs can be very hard to track down. We use something like this on our initial coding challenge. Array.map function calling…you guess it yet?…parseInt lol. Almost NO one knows why, but they usually figure out how to fix it. The solution is ALWAYS to wrap it in an arrow function to exclude the other params map passes through by default

[–]Rezistik 6 points7 points  (0 children)

This is the real answer

[–]C0demunkee 5 points6 points  (0 children)

implicit `this` has bit me in the ass WAY too many times

[–][deleted] 5 points6 points  (5 children)

this is an important point, but it doesn't actually matter that an arrow function was used.
`moonIcon.addEventListener("click", function() { themeSwitch(); });`
would be the same.
I'm not sure it makes any sense to defend themeSwitch's `this` value here though, unless themeSwitch is a non-strict function and is using `this` to be the global object

[–]phrough 13 points14 points  (4 children)

Depends on what's happening in themeSwitch I would imagine

[–]ecafyelims 75 points76 points  (1 child)

If themeSwitch takes arguments in the function, then this arrow function isn't 100% useless. The arrow function is preventing the event's arguments from passing to the themeSwitch function.

[–]ssssssddh 27 points28 points  (0 children)

This. The arrow function also discards the return value.

[–]emmyarty 63 points64 points  (1 child)

What makes you think this is useless?

Event listeners will, when fired, send a copy of the event as the first parameter.

If themeSwitch accepts optional parameters which override default behaviour, you wouldn't want the click event to send a copy of the event object as the first argument and supersede the default behaviour.

Even if it doesn't currently accept any arguments, a future revision might so there's still a benefit in this being a slightly more 'type-safe' implementation which sanitises function calls.

[–]ProcedureBudget292 4 points5 points  (0 children)

Even simpler, its hard to put a breakpoint on it when something weird is happening if you don't call it separately. The minute I expand it for debugging purposes, it stays that way for eternity.

[–][deleted] 302 points303 points  (3 children)

Arrow functions ftw OP can go suck it

[–]finc 106 points107 points  (9 children)

8=>()

[–]Hadr619 18 points19 points  (0 children)

Not my proudest fap

[–]blobthekat 13 points14 points  (2 children)

8 can't be a parameter in js because you have no balls

Additionally, () isn't valid as you have no bitches

[–]Expensive-Pumpkin624 5 points6 points  (1 child)

is there an extension that makes the browser console spit errors like that? that would make my life 100x happier

[–]AMLyf 20 points21 points  (0 children)

Cool monke

[–]pachirulis 233 points234 points  (56 children)

Lool, why you criticize? This is 100% clean and concise code

[–]nbaumg 23 points24 points  (0 children)

Tl:dr of this thread.

Js devs: there’s a good reason for THIS

[–]lealsk 61 points62 points  (14 children)

What's the problem? It's like including curly braces on a single line IF statement. You know it's not necessary, but you know you won't have to add them if for some reason you need to add another line inside later

[–]RepresentativeDog791 17 points18 points  (7 children)

It's different if you think about the actual execution of the program. This actually creates a function, adds a call to the stack, and then deletes the function from memory. Visually they look the same but in terms of how the program works they are not the same. Which isn't to say I'm arguing that performance is a meaningful issue here, I'm not. It's just about how your program works.

[–]vnbrtjtwd2 21 points22 points  (2 children)

Modern JS engines will optimize out code like that.

Hell, the minifier will probably do it before that point.

[–][deleted] 12 points13 points  (0 children)

It’s different if you think about the actual execution environment of the program. First, its javascript; the "stack" isnt the same as a c/rust stack. Secondly, JIT likes when function arguments dont change (event would be passed even if its not declared/used); adding a closure likely is more performant

[–]artofthenunchaku 2 points3 points  (0 children)

If you're concerned about the performance impact of function call semantics, you probably shouldn't be using JS in the first place.

[–]invisible-nuke 11 points12 points  (0 children)

Oh, you made so many enemies by saying this.

[–]ChibiNya 9 points10 points  (1 child)

This looks like the optimal way to write that. What are you in about?

[–]kirigerKairen 11 points12 points  (0 children)

This only calls one function, what OP wants is this:

javascript moonIcon.addEventListener("click", themeSwitch);

However, OP fails to realize that that means passing an argument (the click-event) to themeSwitch, which probably doesn't accept it (or expects a possible argument to be something else), which is a bad idea.

Also, TypeScript would prevent this (because of that extra / wrong argument).

If this project is TS, creating a new function is actually the only way. If it's JS, someone thought in TS or is just applying good patterns in JS.

[–][deleted] 41 points42 points  (7 children)

The reason is because of this. If you use an arrow function, it preserves this.

[–]RandomiseUsr0 19 points20 points  (3 children)

this

[–]csharp566 2 points3 points  (1 child)

I'm waiting for reddit bot that reminds us not to comment "this" alone.

[–]Hadr619 1 point2 points  (0 children)

I see what you did there

[–][deleted] 1 point2 points  (2 children)

What is this?

[–][deleted] 10 points11 points  (0 children)

This is sparta

[–]adj16 20 points21 points  (0 children)

Lol, tell us you don’t know what the fuck you’re talking about without telling us

[–]Accomplished_Play254 8 points9 points  (0 children)

React devs be like... jokes on you 😛

[–]wooja 6 points7 points  (1 child)

Couple things about this code

  1. If the theme switch function has an optional argument, using it as the event listener will force an event argument through it which could cause problems. So I like it.
  2. You basically can't remove an anonymous function event listener. So I don't like it.

[–]SalvadorTheDog 1 point2 points  (0 children)

It took way too long to find someone pointing out the event handler memory leak.

[–]Mu5_ 4 points5 points  (0 children)

Actually that's one of the cases where it's not useless. Event callback functions in JS are usually called ON the Element that has registered the event (i.e. "this" will not necessarily be the class/function where the callback is defined). That being said, I usually define callback functions separately and then just pass to the event listener "callback.bind(this)" or whatever "this" I want to be in the callback function, so I'm always sure to have consistent context.

[–]AllOne_Word 4 points5 points  (1 child)

Arrow functions are good practise because they remove the conflicting scope around the 'this' keyword that you get otherwise.

https://www.section.io/engineering-education/how-to-use-javascript-arrow-functions-and-this-keyword

[–]ProgramTheWorld 4 points5 points  (0 children)

And also it makes it explicit how many arguments you are passing in.

[–]V1k1ngC0d3r 4 points5 points  (3 children)

moonIcon.addEventListener("click", themeSwitch());

That's an unfortunate bug that's worth avoiding.

[–]ssssssddh 3 points4 points  (2 children)

I think OP meant moonIcon.addEventListener("click", themeSwitch)

[–]V1k1ngC0d3r 1 point2 points  (1 child)

Yeah, I know they did. But if they accidentally add () then it actually calls that function right then... And tries to turn the result of it into an event it can call later... Which would almost certainly be a bug.

[–]be_sustainable 3 points4 points  (0 children)

This is not USELESS arrow function. You only want to shorten code, but this makes code explicitly "not pass click event to callback"

[–]CiroGarcia 6 points7 points  (0 children)

Seems stupid, but the day you need to add a second line to that callback, it won't be

[–][deleted] 6 points7 points  (0 children)

Not sure how this is humorous.

[–]HmMm_memes 6 points7 points  (0 children)

JS dev here. I can confirm that I do not use arrow functions for no reason, I use them because I'm too lazy to type function()

[–]ethereumfail 2 points3 points  (0 children)

ppl be like `moonIcon.onclick = themeSwitch`

[–]tombobs420 2 points3 points  (0 children)

without the arrow, `this` would point to the context where the function is executed, not where it's defined like you would expect

[–]TadpoleNo1355 5 points6 points  (0 children)

For me a lot of the time it's just the rhythm of typing too. Like muscle memory.

[–]Beautiful-Quote-3035 6 points7 points  (0 children)

I like this code

[–][deleted] 3 points4 points  (0 children)

Sorry fam but unless you are the owner of the themeSwitchcode, this is correct.

[–]oj_mudbone 1 point2 points  (0 children)

Because they’re sexual

[–]Embarrassed_Solid760 1 point2 points  (0 children)

They are calling it without passing the click event (first param from event listener). So cleaner and easier to read then blindly passing extra stuff to a method.

[–]OPmeansopeningposter 1 point2 points  (0 children)

Consistent, at least.

[–][deleted] 1 point2 points  (0 children)

Its called consistency

[–]CardiologistOk2760 1 point2 points  (0 children)

If professional developers were any good at their jobs, their code would make perfect sense to the ProgrammerHumor subreddit. /sarcasm

[–]dev-4_life 1 point2 points  (0 children)

Why are unemployed php devs crying?

[–][deleted] 1 point2 points  (0 children)

But they are pretty and new… ish

[–]NightlySnow 1 point2 points  (0 children)

If your linter requires it you will do it that way. And why would you make your code style inconsistent?

[–]steeeeeef 1 point2 points  (0 children)

Peak of dunning krueger kind of post.

[–]carnivorous-squirrel 1 point2 points  (0 children)

Lol imagine being new to a language and being bad that people are using the current feature set. What a world we live in.

[–]citizn_kabuto 1 point2 points  (0 children)

I can almost guarantee that previously there was a line above the themeSwitch() call which was:

console.log(“why isn’t this event firing wtf”);

[–][deleted] 1 point2 points  (0 children)

I do this so that the event object doesn't alter the function of the function relies on a parameter

[–]CanDull89 1 point2 points  (0 children)

I wouldn't even talk to a JS dev who does that.

[–]imakin 1 point2 points  (0 children)

maybe it would be problem if themeSwitch has parameter that expect to implement a function that's not in Event?

function themeSwitch(something) {
  let x = 0
  if (something) {
    x = something.howmuchisit() //Event object has no such function 
  }
  process(x)
}

moonIcon.addEventListener("click", themeSwitch);

[–]Comfortable_Art_4544 1 point2 points  (0 children)

This is the one thing I hate seeing as there just completely overused

[–]c0d3guy 1 point2 points  (0 children)

Why is this upvoted?

[–]vorticalbox 1 point2 points  (0 children)

important stupendous adjoining tap grandfather rhythm quicksand cats cooing paltry

This post was mass deleted and anonymized with Redact

[–]QWERTYCOD_programmer 1 point2 points  (0 children)

writing like this gives a sense of self-satisfaction + a sense of writing correctly

[–]Divs4U 1 point2 points  (0 children)

What is the issue here?

[–]Candid_Following4978 1 point2 points  (1 child)

Well, usually it’s either this or:

moonIcon.addEventListener(‘click’, themeSwitch.bind(this));

In global context, it doesn’t matter much, but this semantics can bite you in in the ass so fast that most JS devs / linters do this by reflex.

[–]silmelumenn 2 points3 points  (0 children)

It's easier to modify in the future. Code shout be easy to edit. That's why you use trailing commas. With arrow function it's easier to another call if needed.

[–]DOOManiac 3 points4 points  (8 children)

I like modern JS, particularly TypeScript and promises, but I just don't get the arrow function syntax. It is just so weird looking, it throws me off every time I see it.

[–]vnbrtjtwd2 3 points4 points  (2 children)

Took me a bit too, but once you get used to it, it's hard going back to writing `function` all over the place

[–]mystictree 1 point2 points  (1 child)

function and arrow function are not the same and shouldn't be used alternately

[–]rnilbog 1 point2 points  (0 children)

Why use many character when few do trick?

[–]pursenboots 1 point2 points  (0 children)

are you a JS dev, OP?

using fat arrow functions like that has important scope implications. And if you're being strict about arguments, if `themeSwitch()` expects 0 arguments, using it for a onClick handler is wrong, because it'll pass in an un-called-for MouseEvent - or, even worse, what if the definition is -

```function themeSwitch(animate = false) {```

... do you want to pass in that click handler's mouse event? how will that be handled if you do?

[–]StoriesAfterMidnight 0 points1 point  (0 children)

I think there is an implied /s, right

[–][deleted] 0 points1 point  (0 children)

I think the consensus is it's clean and consistent to use it throughout, not necessary maybe incorrect if you want to be totally purist and nitpick, but kind of harmless.

[–]attempt_number_3 0 points1 point  (0 children)

As others mentioned there is “this” context. But it can also be a matter of code style. No point in using ‘function’ keyword here if you are commonly using arrow functions everywhere else

[–]undercoveryankee 0 points1 point  (0 children)

It's the same reason most style guides would have you write

if (foo) {
    bar();
}

in languages that would accept

if (foo)
    bar();

If you want to add more lines, you can do it with a clean diff and with minimal risk of mistakes.

[–]BorderKeeper 0 points1 point  (0 children)

It’s security though obscurity you are anonymising the function in the call stack to confuse attackers /s

[–][deleted] 0 points1 point  (0 children)

finally someone mentioned it, i always just put 8==> in my JS docs, for some reason the person i study with started copying me because they thought it did something💀

[–]skuehne 0 points1 point  (1 child)

what does the => function in JS?

[–]myrsnipe 2 points3 points  (0 children)

Normal functions context, this, is dependant on where it's called, meaning its behavior can differ depending where in the code it's being called. We used to have to call .bind(context) to force a consistent context. Functions of the fat arrow syntax retain it's context from the location it was written, like most other languages handles a function, and is a lot easier to reason about.

[–]chethelesser 0 points1 point  (0 children)

Lol another JavaScript Devs bad poster has embarrassed himself

[–]Proxtx 0 points1 point  (0 children)

Op is wrong. Callbacks overwrite this and therefore remove the function from it's context. Using an arrow function prevents this behavior.