r/programming • • Jul 25 '13

CoffeeScript's Scoping is Madness

http://donatstudios.com/CoffeeScript-Madness
207 Upvotes

315 comments sorted by

View all comments

Show parent comment

1

u/munificent Jul 26 '13

In JS you can always stick a function in your private variables.

Yup, but you lose dynamic dispatch in the process. For example:

abstract class Tool {
  void _click();
}

class Paintbrush extends Tool {
  void _click() { ... }
}

class Eraser extends Tool {
  void _click() { ... }
}

Here we've got a couple of derived classes that override a private method. In Dart, within the library where these are defined, you can call _click() and it will dynamically dispatch to the right method if you have a Paintbrush or an Eraser.

2

u/smog_alado Jul 26 '13

Thats what I was talking about when I mentioned the problem of protected methods. This is OK for Dart but its though for Coffeescript because in that case you want to be able to have vanilla JS classes inheriting from your CS class and then its tricky to have a property be visible by the child class without also making it fully public.