This project is archived and is in readonly mode.

#642 ✓wontfix
Scott Kyle

Class mutators order-dependent in 1.2.2 and 1.3

Reported by Scott Kyle | April 21st, 2009 @ 05:45 AM | in 1.3.0 rc2 (closed)

Class::implement is looping through properties and evaluating class mutators as they are encountered now, which means that the mutations will have different results depending on order (i.e. putting Implements at the end will overwrite the Class methods). There are many side effects of this. Almost all JavaScript engines loop through object literals in order of definition, however that is not a part of the standard.

I propose moving the mutations before calling implement() in the Class function:


function Class(params){
	
	if (params instanceof Function) params = {initialize: params};
	
	var newClass = function(){
		Object.reset(this);
		if (newClass._prototyping) return this;
		this._current = $empty;
		var value = (this.initialize) ? this.initialize.apply(this, arguments) : this;
		delete this._current; delete this.caller;
		return value;
	}.extend(this);
	
	for (var mutator in Class.Mutators){
		if (!params[mutator]) continue;
		var value = Class.Mutators[mutator].call(params, params[mutator]);
		if (value == null) delete params[mutator];
	}
	
	newClass.implement(params);
	
	newClass.constructor = Class;
	newClass.prototype.constructor = newClass;

	return newClass;

};

This will make mutators work consistently independent of order (unless they literally conflict with each other) and give the mutators access to all the Class's params whereas before they only have access to whatever had been looped through already and attached to the prototype.

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

Pages