I distinctly remember lots of var that = this; in JS code back then, which wasn't required anymore when using CoffeScript.
I distinctly remember lots of var that = this; in JS code back then, which wasn't required anymore when using CoffeScript.
javascript is first and foremost functional no matter how hard MS and others have tried to hammer it into a more typical OOP language.
jquery vs mootools/scriptaculous/etc.
jquery won for a reason, it's just flat out a better experience in terms of code specifically because it uses a functional approach in its api rather than an OOP approach.
I feel like you're just saying that because you like functional code. I'm sure that when they've added syntax to make certain functional things easier to type, you didn't respond "it's awkward, so don't do that, write it in an entirely different way instead".
Regardless of what is "better", which tends to differ based on situation, there was no need for the awkwardness. Classes weren't bad to use, it was just that declaring them had some pointless busywork.
If you don't the only response I can have is to go learn it.
This isn't about functional being better, it's about functional being more fluid to use in javascript.
Especially when you're not dealing with the DOM, sometimes objects work quite well.
The original awkwardness does not show that javascript "was never designed to be used like a classic OOP language".
Nor is it why jquery worked well.
And adding these slight changes is not trying to "hammer" javascript into being "more typical OOP".
this is disingenuous and I'm ending it here. MS spent years trying, and initially failing, to get javascript to work in a more traditionally OOP way.
describing that as slight is something else.
I'm not being disingenuous. Other people can't read your mind. Other people aren't experts on the same things you are.
And specifically, I described the class keyword as slight.
Don't be an asshole by accusing people of things they're not doing.
do not try and downplay something just because you want it to be true.
And I stand by saying there was no need for the awkwardness with classes.
What did I downplay? You still haven't said what they did. I can't be downplaying a thing that isn't part of the conversation.
----
edit: But also, let me point something out.
what you're calling "awkwardness with classes" is incorrect. they were _functions_ that you could attach state to, some of that state could, itself, be callable functions. That's a large part of _why_ javascript has prototype inheritance.
javascript was primarily functional with some features that allowed a bit of OOP sprinkled in.
To be extra direct there: I didn't say the effort was small, I said that change was small. You can have a big effort for a small change. So you definitely misread me there.
But when you talked about "hammering" it into a more OOP language, I thought you were talking about big changes or many changes.
> what you're calling "awkwardness with classes" is incorrect. they were _functions_ that you could attach state to, some of that state could, itself, be callable functions. That's a large part of _why_ javascript has prototype inheritance.
Does it matter if the "class" itself is a function or an object or something else entirely? It makes thingies that have the prototype applied and you can do .foo on.
But classes you make with the keyword are still functions, aren't they? So what's the big betrayal?
But more importantly, this all started because I pointed out that javascript is a functional language.
This remains true, which is why writing functional code in javascript ends up with a better experience, and that's a large part of why jquery won.
Brendan Eich, the creator of javascript, was heavily influenced by. Scheme is functional so I'm not saying anything outlandish here.
https://softwareengineering.stackexchange.com/questions/1941...
> I've never used Self myself, but I believe that JavaScript's extensive use of prototypes came from Self.
> As for Scheme's influence, you need look no further than JS's first-class functions and lexical scoping (okay, so JS doesn't implement full lexical scoping in the way Scheme does, it implements function-level scoping, but still, it's close).
(Some of the distinctions you're making still make no sense to me because you think they're so evident you won't elaborate, but at this point it's definitely not worth the effort.)
Fixing _this_ is a good point, though.
// Doesn't work, <this> is <window>.
document.body.addEventListener("click", function(event) { this.handleClick(event) })
vs. document.body.addEventListener "click", (event) => @handleClick(event)
You only needed a .bind(this) in the plain JS version, but it felt like surprisingly few people knew this back then.Interestingly enough, the current version of CoffeeScript compiles this code into a ES6 arrow function itself, but I think back then they used bind() in the transpiled JS.