I have always set up my Javascript using objects like below:
if (!FooBar_Old) var FooBar_Old = {};
FooBar_Old.UI = {
test_str : 'it works'
, test: function() {
console.log(this.test_str);
}
};
// FooBar_Old.UI.test();
However recently I have been wanting to convert these to real classes
to take advantage of the initialize constructor. I took a first pass
at this, and can't get it working.
This post is two questions:
#1 Which method do you use in your javascript programming Objects or
Classes?
#2 What am I doing wrong with my class declaration below?
// Class Based (Doesn't work)
if (!FooBar) var FooBar = {};
FooBar.UI = new Class.create({
test_str : 'it works'
, initialize: function(options) {
// Whatever
}
, test: function() {
console.log(this.test_str);
}
});
// FooBar.UI.test();
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---