You'd probably do better by using a "proper" class instead of this
form of static/structure with methods approach.
var FooFactory = Class.create({
initialize : function(){
this.items = new Hash();
},
set : function(key, val){
this.items.set(key, val);
},
get : function(key){
return this.items.get(key);
},
test : function(){
console.log(this.items);
}
});
var factory = new FooFactory();
http://prototypejs.org/api/class/create
On Oct 11, 11:36 am, Morten <[EMAIL PROTECTED]> wrote:
> NVM, a missing return statement..
>
> On Oct 11, 5:49 pm, Morten <[EMAIL PROTECTED]> wrote:
>
> > Hi. I'm trying to create a factory class for churning out objects. But
> > I'm running into some basic problem as illustrated here:
>
> > var FooFactory = Class.create();
> > FooFactory.items = new Hash();
>
> > FooFactory.get = function(id) {
> > this.items.get(id);
>
> > };
>
> > FooFactory.set = function(id, value) {
> > this.items.set(id, value);
>
> > };
>
> > FooFactory.test = function() {
> > console.log('Items:'+this.items.inspect());
>
> > };
>
> > If I run this, and execute in Firebug console, the "get" method
> > doesn't work:
>
> > >>> FooFactory.set('5','aaaa');
> > >>> FooFactory.test();
>
> > Items:#<Hash:{'5': 'aaaa'}>>>> FooFactory.get('5').length;
>
> > TypeError: FooFactory.get("5") is undefined
>
> > Anyone have a tip? I can do FooFactory.items.get('5') just fine, but
> > would like to understand what I'm doing wrong.
>
> > Thanks,
>
> > Morten
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---