Prototype and Options
Tired of seeing Object.extend and this.options everywhere in your Prototype code ? Try this Options mixin !
example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
var Widget = Class.create({ defaultOptions: { className: 'widget', theme: 'BeOS' }, initialize: function(element, options) { this.setOptions(options); ... } }); // For 1.6 Class.mixin(Widget, Options); // For 1.5 Object.extend(Widget.prototype, Options); |
2 comments
Comments
-
Very nice, Samuel. It would be also very nice if you could show some real -life examples using prototype's new inheritance features. best, kangax
-
kangax: real examples are coming really soon since we are using something like this to rewrite Prototype Window Class" with Sébastien Gruhier. By the way, you pointed out the real tricky point which is how to use it with inheritance (particulary how to merge options from superclass to subclasses...) Stay on tune :)