Pastie now auto-senses if line-wrap is a bad or good idea. Feedback?
## mark a section (Learn more)
This paste will be private.
SomeModule = { methodFromSomeModule: function() {} }; SomeOtherModule = { methodFromSomeOtherModule: function() {} }; Person = Class.create(function() { // mixin instance methods to prototype Class.add(this, SomeModule); // mixin class methods Class.mixin(this, SomeOtherModule); // private variables just work var secret = 'I am a private variable!'; // private methods just work function secretFunction() { return secret; }; // add class methods one at a time this.anotherClassMethod = function() { return secretFunction(); }; // add instance methods one at a time this.prototype.anotherInstanceMethod = function() { return secretFunction(); } // methods returned are added to prototype return { initialize: function() {}, moreInstanceMethods: function() { return secretFunction(); } }; }); Person.anotherClassMethod() //=> 'I am a private variable!' var joe = new Person(); joe.anotherInstanceMethod() //=> 'I am a private variable!'
From the Design Piracy series on my blog: