Loading ...
Sorry, an error occurred while loading the content.

176Re: [caplet] Mutability of functions in ECMAScript

Expand Messages
  • Kris Zyp
    Apr 6, 2008
      > If functions were immutable, joining would be a transparent optimization.
      >
      Apart from the theoretical potential for backward incompatibility, why
      >
      isn't this a better solution? I suspect that very few programs rely on
      >
      mutating actual functions
      Really? It is actually even used in ADsafe's core library. Mutating functions is pretty core functionality, and AFAIK it is necessary to form multi-level prototypical inheritance. If I want object A to delegate/inherit from preexisting object B, I must create a function and set the prototype (a mutation) to object B and then construct with that function. See the beget function in ADsafe.
      I would extremely surprised if function mutation is less common than some of the things that the ES3.1 and ES4 groups have to maintain for backwards compatibility (the latest was being able override the Error built-in). I have used it other situations as well, like using storing a list of listeners on a AOP advising function. AOP style event listeners are common in popular JS libraries as well, and I would imagine they use such techiniques as well.
       
      > (as opposed to creating mutable objects that are
      > callable as functions, or
      mutating Function.prototype) .

      How do make a regular object callable?
       
      Kris
       
       
       
      ----- Original Message -----
      Sent: Sunday, April 06, 2008 9:17 AM
      Subject: Re: [caplet] Mutability of functions in ECMAScript

      Mark Miller wrote:
      > On Sat, Apr 5, 2008 at 9:09 PM, Kris Zyp <kris@sitepen. com> wrote:
      >> AFAIK, no implementation has ever actually done this "joining", and I
      >> believe ES3.1 and ES4 will very likely dissallow joining to prevent it from
      >> ever happening in the future.
      >
      > Yes, that's what we decided. ES3.1 and ES4 will be deterministic in
      > this regard. No joining.

      If functions were immutable, joining would be a transparent optimization.
      Apart from the theoretical potential for backward incompatibility, why
      isn't this a better solution? I suspect that very few programs rely on
      mutating actual functions (as opposed to creating mutable objects that are
      callable as functions, or mutating Function.prototype) .

      --
      David-Sarah Hopwood

    • Show all 13 messages in this topic