question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Not binding an anonymous function in Coffeescript executes with `this` bound to `window` ... but arrow functions do not provide a non-null `this`

See original GitHub issue
 _.defer -> @someWindowProp?

I get this output:

_.defer => { ... }

Technically, this is not preserving behaviour since this is now null and this causes an exception to be thrown. In the Coffeescript runtime (i.e: using just function then you get a case where you would end up just being run in the window context. In most cases in our code base, it’s actually an error! (someone thought they were bound but were not and did a null check for other reasons) but I guess technically this goes against “out of the box correctness”

Not sure how to fix – I have a few ideas but not 100% there.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
hilts-vaughancommented, Apr 20, 2018

Thanks for taking a look. That’s what I gathered as well. As I said, in my case most of these are actually in error and someone isn’t actually looking for a window prop, rather, a class prop but forgot to bind, so there was already a logic bug. In some ways, decaffeinate did me a favour. 😉

Thanks.

1reaction
hilts-vaughancommented, Apr 20, 2018

oops, I may have simplied too much. I’ll try and create a REPL for you – sorry, I can’t link to proprietary code and may have “trimmed” out the source of the problem.

Lemme do that for you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing an arrow function vs passing the function
The second case an anonymous function is created which executes the handleChange method and and thereby providing it the context .
Read more >
coffee-script/index.html.erb at master - documentation
Launch an interactive CoffeeScript session to try short snippets. Identical to calling <tt>coffee</tt> with no arguments.
Read more >
Top 7 Reasons To Love CoffeeScript
Function binding has a similar shortcut. When defining a function I need to make sure is scoped (or "bound") to the current "this"...
Read more >
CoffeeScript
The fat arrow => can be used to both define a function, and to bind it to the current value of this, right...
Read more >
IcedCoffeeScript - About Me
IcedCoffeeScript is a superset of CoffeeScript. The iced interpreter is a drop-in replacement for the standard coffee interpreter; it will interpret almost ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found