Just declare a static property for the counter.
var Person = Class.create({
initialize: function(name) {
Person.count++;
this.name = name;
}
})
Person.count = 0;
new Person('John'); // Person.count == 1
new Person('Matt'); // Person.count == 2
- kangax
On Apr 13, 1:33 pm, StackOverflow <[EMAIL PROTECTED]> wrote:
> Hello, I'd like to have a counter for instances of my classes.
> Separately for each class, but code for counter should be installed in
> one parent class. Any ideas?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Spinoffs" 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/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---