Skip to content

Instantly share code, notes, and snippets.

@juandopazo
Created June 2, 2011 13:59
Show Gist options
  • Select an option

  • Save juandopazo/1004493 to your computer and use it in GitHub Desktop.

Select an option

Save juandopazo/1004493 to your computer and use it in GitHub Desktop.
Quick note about objects as YUI3 attributes default values
/**
* 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 }
}
});
@juandopazo
Copy link
Copy Markdown
Author

It appears that Y.Array() returns not an empty array but an array with an undefined first item. This is probably a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment