
Extends Class.
Implements properties into a class preserving the previous state of methods so you can reference them..
OriginalClass = Class.refactor(OriginalClass, newProperties)
The .implements method of class allows you to inject new properties into an existing class. Where collisions of objects occur, they are blended. For example:
var Animal = new Class({ options: { color: 'brown', says: 'hissss' } }); Animal.implement('options', {says: 'meow'}); // Animal.prototype.options is now {says: 'meow', color: 'brown'};
However, this is not the case with methods, which are overwritten.
Class.refactor, however, allows you to reference the previous state with this.previous. For example:
var Cat = new Class({ energy: 0, eat: function(){ this.energy++; } }); Class.refactor(Cat, { eat: function(){ this.previous(); //energy++! alert("this cat has " + this.energy + " energy"); } });
Note also that changes to a class affect the subclasses of that class.
© Linux.ria.ua, 2008-2024 |