Class method addition and replacement (was Re: AOP Compatibility)

Garrett Smith dhtmlkitchen at
Sun Apr 6 13:49:58 PDT 2008

On Thu, Apr 3, 2008 at 5:20 PM, Peter Hall <peter.hall at> wrote:
> If you want mutability, you can define methods as vars in the first place.
>  class Foo {
>   // can be modified on a per-instance basis
>   public var f : function (a:T):S = function (a:T):S {
>       return null;
>   }
>  }

A common idiom is to have a default value in the ADT's prototype. (I'm
calling a constructor-with-a-prototype an "ADT" -- ES3, which doesn't
have true "class" classes).

ES3 example:

function Button() { }

Button.prototype = {
  ondepress : function(){},
  _isDepressed : false

var b = new Button;
b.ondepress = buttonDepressed;

- b - just got a new instance property: ondepress.

So when defining an ES4 class, instead of putting a default -
ondepress - in the prototype, a dummy function will be added to the

I'm not understanding the syntax well enough to post an example.

This will have the result of more function objects being created for a
program that does not use - ondepress - for Button instances. Would
the Button class be better off by having a private EMPTY function? Or
maybe that goes on a larger scale, to the event notification system,
but then that wouldn't work unless the event system's empty Function
instance was immutable.


>  >
>  _______________________________________________
>  Es4-discuss mailing list
>  Es4-discuss at

More information about the Es4-discuss mailing list