michaelficarra / CoffeeScriptRedux

:sweat: rewrite of the CoffeeScript compiler with proper compiler design principles and a focus on robustness and extensibility

Home Page:https://michaelficarra.github.com/CoffeeScriptRedux/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Confusing behaviour when inheriting from classes with bound methods

jameswilddev opened this issue · comments

I understand why this is happening (methods are rebound in the constructor) but this is somewhat confusing; if you inherit from a class and don't call super in the constructor, or call it too late, the bound functions against the class are left unbound:

class abc
  x: => 4

class def extends abc
 constructor: ->
    # Uncomment this to make a.x != b.x
    # super
    return

a = new def()
b = new def()

alert "#{a.x is b.x}"

This could be fixed by moving the rebindings out of the constructor and into a generated function called automatically before any constructor anywhere down the inheritance tree is called.

Wait, I'm sorry, I got confused and posted this here rather than in the main CoffeeScript repository.