News for hackers. Stuff that matters.
Re:Announcing CoffeeScript 2 by kbenson on Monday September 18, 2017 @12:12PM (#15277128)
> So a CoffeeScript => is now output as =>

Wait, using the arrow function notation doesn't bind this, arguments, super, or new.target[1] in javascript, as opposed to the normal function syntax. Not being a user of coffeescript, did coffeescript not do that already, or did they also throw in code to change that in the generated code?

It seem to me it would make sense to map items that match conceptually, not just notationally (unless it's common to have both coffeescript and JS side by side). Can someone comment on how this is handled?

1: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...

Edit: Added "in javascript" after reference to make it obvious I was talking about JS behavior for the binding.

Re:Announcing CoffeeScript 2 by Nullabillity on Monday September 18, 2017 @12:17PM (#15277165)
CoffeeScript did already bound `this` for `=>`. There is also `->`, which is morally equivalent to JS' old-style `function`.
Re:Announcing CoffeeScript 2 by thechewanater on Monday September 18, 2017 @12:25PM (#15277230)
In coffeescript 1.x fat arrow functions already bound "this", although binding "arguments" is an actual change.

http://coffeescript.org/#breaking-change-fat-arrow

Re:Announcing CoffeeScript 2 by madeofpalk on Monday September 18, 2017 @12:38PM (#15277342)
Coffeescript's => binds this. Javascript's => also binds this (more or less)

Seems to map fairly well conceptually.

Re:Announcing CoffeeScript 2 by kbenson on Monday September 18, 2017 @12:57PM (#15277528)
> Javascript's => also binds this (more or less)

Javascript's => doesn't bind this though, and function does, which was my point (and is what the reference I included was saying). That's a specific change in JS, and either coffeescript had code in place to emulate the current behavior in prior versions where they used function(), or they have code in place now to emulate function() now that they're using =>.

I'm going to update my original comment to be a bit more clear on what I was saying.

Re:Announcing CoffeeScript 2 by irishsultan on Monday September 18, 2017 @01:26PM (#15277760)
Old Coffeescript behaviour for => was to use a function where this was bound to that of the environment. This seems subtly different from having this not being bound at all (in that you can't rebind it under the new translation), but that's unlikely to have been a common use case.

The main other difference seems to be that there is no arguments object for the local function anymore, although once again that's unlikely to be a problem in most functions defined with a fat arrow.

As someone else also said, there were two ways to define functions, one using =>, one using -> the latter maps to a normal JS function.

Re:Announcing CoffeeScript 2 by kbenson on Monday September 18, 2017 @01:35PM (#15277845)
> Old Coffeescript behaviour for => was to use a function where this was bound to that of the environment.

Okay, so it sounds like coffeescript 1.0 => was effectively doing what JS => does now, so it makes sense to move to the newer JS syntax Thanks for elaborating! (It's interesting how "binds this" can, and was interpreted in multiple ways, Perhaps there's a better, more specific wording I could have used to cut through those misunderstandings, whether they be with those that replied or me reading their replies).

Re:Announcing CoffeeScript 2 by likeclockwork on Monday September 18, 2017 @01:35PM (#15277849)
You have it backwards. => in JS binds this, and => in coffee used to bind this also but now just emits JS' =>. => in JS was pretty much taken from coffee, there was no prior version of => in JS.

Coffee also has -> which desugars to a regular function() {}

Re:Announcing CoffeeScript 2 by madeofpalk on Monday September 18, 2017 @01:34PM (#15277829)
> Javascript's => doesn't bind this though

I think we're getting our wires crossed. Both Javascript and CoffeeScript have (more or less, for the common use cases) the same `this` behaviour for =>. It preserves the `this` value from the context.

Re:Announcing CoffeeScript 2 by kbenson on Monday September 18, 2017 @01:39PM (#15277880)
Yes, that's what was explained in the sibling. There's a lot of confusion on what "binds this" can mean, and while I thought you might have been misinterpreting me, I may have been misinterpreting you. I was using the terminology that MDN uses in reference to the function arrow, but in the context of this question, some additional elaboration might have been useful to distinguish exactly what "this" is when it's bound (the calling environment, or the current subject being called on as is often the case).