Array is a constructor for an array. [ ] is an instance of an Array.
gebura - You'll probably have to create your own collections when you need them. You might keep an internal array as a property.
Code:
ListeCommandes = function ListeCommandes( type ) {
this.type = type.
this._items = [ ];
};
ListeCommandes.prototype = {
,addCommands : function( commandArray ) {
// might need a typeCheck here.
this._items = this._items.concat( commandArray );
}
,getItems : function() {
return this._items.concat(); // Defensive copy; see Bloch.
}
...
};
You could use YUI extend and create an abstract Collection superclass, then have a List class that extends collection, then have ListeCommands extend List.
Code:
YAHOO.extend( com.acme.ListeCommands, com.acme.List, {
// ListeCommands' List override methods here.
});
I've used Stack functionality for CommandStack, so I can have push, pop. This makes undo/redo very easy. (this may be not what ur trying to do). Iterator functionality is nice too. Collections are very useful. You just have to write and them yourself in javascript. It is not easy.
Bookmarks