This project is archived and is in readonly mode.

#940 ✓wontfix

Loop on Class Mutators should be after implementing methods

Reported by elado | June 26th, 2010 @ 03:01 PM

I wrote a Class Mutator which messes with the initialize method of a class. Inside the mutator function, the initialize (this.prototype.initialize) is available only if the mutator's property was declared after the initialize property.

Class.Mutators.M=function () {
  this.prototype.initialize=function () { alert("Mutator is here"); }

var X=new Class({
  initialize:function () {}

new X(); // no alert

var Y=new Class({
  initialize:function () {},

new Y(); // alert 'Mutator is here'

It happens, of course, because the loop inside Class#implement goes thru all properties in the order they were defined in an object, and executes Mutators in the same loop. In that case, M mutator is called before the initialize is defined.

I suggest to separate it into two loops: the first will ignore mutators and call .implement only for all other properties, the second will only apply mutators.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Referenced by