5 ms·
Coffeescript's => binds this. Javascript's => also binds this (more or less) Seems to map fairly well conceptually.
by madeofpalk 9y ago
Coffeescript's => binds this.
Javascript's => also binds this (more or less)
Seems to map fairly well conceptually.
- kbenson 9y ago> 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.
- irishsultan 9y agoOld 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.
- kbenson 9y ago> 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).
- madeofpalk 9y ago> 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.
- kbenson 9y agoYes, 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).
- likeclockwork 9y agoYou 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() {}