I was trying to implement a ruby-like separation of class and instance methods inside a module using `included`, here's what it looks like:Validatable = new JS.Module({InstanceMethods: new JS.Module({...}),ClassMethods: new JS.Module({...}),extend: {included: function(klass) {klass.include(this.klass.InstanceMethods);klass.extend(this.klass.ClassMethods);}}}However, `this.klass.ObjectMethods` and `this.klass.ClassMethods` are undefined. How do I get access to them correctly?
To explain what's going on here: you've made InstanceMethods and ClassMethods as instance properties of the Validatable module, so they will become instance properties of whatever you mix the module into. The the included() function, `this` refers to the Validatable module, so the value of `this.klass` is Module.What you probably want to do is move the modules into the `extend` block, and just use `this.InstanceMethods` to refer to them in included().
In the same vein, if youinclude()a module that has a singleton method calledincluded, that method will be called. This effectively allows you to redefine the meaning ofincludefor individual modules.
However, I must ask you a bit more about included(). This is from the docs:In the same vein, if youinclude()a module that has a singleton method calledincluded, that method will be called. This effectively allows you to redefine the meaning ofincludefor individual modules.Yet you're saying that InstanceMethods and ClassMethods, if defined as module's instance properties, become instance properties of whatever I mix the module into. Does that mean that included() is simply a callback and by providing this callback I don't prevent module's instance properties from mixing in?