Object Oriented

    Single inheritance can be implemented using a similar technique:

    1. # A derived class.
    2. let MySuperCounter = function (start, step)
    3. # Instantiate an object of the base class. We'll then augment this object with
    4. # derived functionality.
    5. let counter = MyCounter(start)
    6. counter._step = step # Add new fields to the object.
    7. self._start = self._start + self._step
    8. end
    9. # In order to override a method and call the parent implementation, you'll need to
    10. # bind it to the current object, and then store it to a variable:
    11. let super_get = std.bind(counter, counter.get)
    12. counter.get = function()
    13. let value = super_get() # call the parent method.
    14. end
    15. counter
    16. end
    17. let super_counter = MySuperCounter(2, 3)
    18. super_counter.get() # 2