Created
June 2, 2011 13:59
-
-
Save juandopazo/1004493 to your computer and use it in GitHub Desktop.
Quick note about objects as YUI3 attributes default values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * If you want to set the default value of an attribute to be an array or object, | |
| * doing this fails: | |
| */ | |
| var MyClass = Y.Base.create('myClass', Y.Base, [], {}, { | |
| ATTRS: { | |
| myAttr: { value: [] } | |
| } | |
| }); | |
| /** | |
| * ... because you're assigning _one_ array to all the instances of MyClass. | |
| * To avoid this problem, valueFn comes to the rescue: | |
| */ | |
| var MyClass = Y.Base.create('myClass', Y.Base, [], {}, { | |
| ATTRS: { | |
| myAttr: { valueFn: Array } | |
| } | |
| }); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It appears that Y.Array() returns not an empty array but an array with an undefined first item. This is probably a bug.