Prototype-UI Release Candidate 0 |
UI. OptionsMixin to handle options argument in initializer pattern. TODO: find a better example than Circle that use an imaginary Point function, this example should be used in tests too. It assumes class defines a property called options, containing default options values. Instances hold their own options property after a first call to setOptions. Examplevar Circle = Class.create(UI.Options, { // default options options: { radius: 1, origin: Point(0, 0) }, // common usage is to call setOptions in initializer initialize: function(options) { this.setOptions(options); } }); var circle = new Circle({ origin: Point(1, 4) }); circle.options // => { radius: 1, origin: Point(1,4) } AccessorsThere are builtin methods to automatically write options accessors. All those methods can take either an array of option names nor option names as arguments. Notice that those methods won’t override an accessor method if already present.
Common usage is to invoke them on a class to create accessors for all instances of this class. Invoking those methods on a class has the same effect as invoking them on the class prototype. See <classMethod> for more details. Example// Creates getter and setter for the "radius" options of circles Circle.optionsAccessor('radius'); circle.setRadius(4); // 4 circle.getRadius(); // => 4 (circle.options.radius) Inheritance supportSubclasses can refine default options values, after a first instance call on setOptions, options attribute will hold all default options values coming from the inheritance hierarchy. Summary
|
Extends object’s options property with the given object
setOptions: function( options )
Computes the complete default options hash made by reverse extending all superclasses default options.
allOptions: function()
Creates default getters for option names given as arguments.
optionsGetter: function()
Creates default setters for option names given as arguments.
optionsSetter: function()
Creates default getters/setters for option names given as arguments.
optionsAccessor: function()