On Sep 9, 7:29 am, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> Hi all,
>
> I thought of a wrinkle today:  Mixins.  This new mechanism modifies
> function instances if they override base class functions (it leaves
> them alone if they don't).  So if you mix in something that has a
> function with the same name as a parent class's function, we will set
> a $super property on the mixin function's instance.  That seems wrong
> to me, mixins should be read-only as far as the mechanism is
> concerned, IMHO.
>
> Now, in _practical_ terms, unless the mixin function calls $super
> (which seems an odd thing for a mixin to do, but I can come up with an
> edge case use case for it), it doesn't matter much.  But if A) the
> mixin function does (presumably optionally) call $super, and B) more
> than one class mixes the mixin in, AND C) the mixin overrides one of
> the functions in at least one of those classes, you get class
> crosstalk -- a very bad thing.
>
> My first thought for how to deal with this was stupid and I'll spare
> you.
>
> My *second* (hopefully not stupid) thought was to mark mixin functions
> with a property telling us to leave them alone.  I see two
> ramifications to doing that:

Well, technically mixins are already "marked" by being an object,
rather than a function :)

// Constructor/"Class" (a function)
function Person(){}

// Mixin (not a function, although it could be (!))
var Observable = {
  observe: function(){ ... },
  stopObserving: function(){ ... }
}

I don't think there was ever such requirement for mixins in Prototype,
though, so there's a chance people are using function-based mixins
(for whatever reasons):

function Observable(){ ... };

Object.extend(Observable, {
  observe: function(){ ... },
  stopObserving: function(){ ... }
});

[...]

--
kangax
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to prototype-core@googlegroups.com
To unsubscribe from this group, send email to 
prototype-core-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to