Object Oriented
Single inheritance can be implemented using a similar technique:
# A derived class.
let MySuperCounter = function (start, step)
# Instantiate an object of the base class. We'll then augment this object with
# derived functionality.
let counter = MyCounter(start)
counter._step = step # Add new fields to the object.
self._start = self._start + self._step
end
# In order to override a method and call the parent implementation, you'll need to
# bind it to the current object, and then store it to a variable:
let super_get = std.bind(counter, counter.get)
counter.get = function()
let value = super_get() # call the parent method.
end
counter
end
let super_counter = MySuperCounter(2, 3)
super_counter.get() # 2