On Jul 11, 10:18 am, Jeff Watkins <[EMAIL PROTECTED]> wrote: > Alex, I like the class definition function method with the exception > of returning a hash. It seems like it ought to be one way or the > other. But then, I've never had any problem just going long-hand with > my class definitions.
Returning the hash isn't strictly necessary. You could just use: var Person = Class.create(function() { Class.add(this, { // instance methods defined here }); }); > One small quibble, I think it might be a little more clear were the > class explicitly passed to the closure rather than using this. For > most people, this is synonymous with an instance. Yes, the very first version I wrote did in fact do that. I changed it on the advice of some friends after they looked at the syntax. Perhaps that change was for the worse. The original had syntax that looked like: var Person = Class.create(function(self) { self.classMethod = function() {}; self.prototype.instanceMethod = function() {}; Class.add(self, Module); // ... }); On another note, I missed a rather neat usage in the original usage Pastie. Conditionally adding methods: var Person = Class.create(function() { if (someCondition) { Class.add(this, { // instance methods }); } else { Class.add(this, { // different instance methods }); } }); var Person = Class.create(function() { var methods = { // default instance methods }; if (someCondition) { Object.mixin(instanceMethods, { // nuke some methods }); } Class.add(methods); }); --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype: Core" group. To post to this group, send email to prototype-core@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/prototype-core?hl=en -~----------~----~----~----~------~----~------~--~---