Skip to content

Instantly share code, notes, and snippets.

@joseph
Last active August 29, 2015 13:57
Show Gist options
  • Save joseph/9771701 to your computer and use it in GitHub Desktop.
Save joseph/9771701 to your computer and use it in GitHub Desktop.
JS class pattern [4]
// AMD module definition:
define(function (require) {
// An instantiable class:
var ClassName = function () {
// All private instance data is stored in this._
this._ = {};
this._initialize();
}, PROTO = ClassName.prototype;
// A constant
PROTO.MEANING_OF_LIFE = 42;
// A "private" method begins with an underscore:
PROTO._initialize = function () {
}
// A public method does not begin with an underscore:
PROTO.update = function () {
}
return ClassName;
});
@joseph
Copy link
Author

joseph commented Mar 27, 2014

I played around with K as $, which seems less idiosyncratic, and happily it should annoy jQuery acolytes, but it felt a bit Perl-like. Currently I'm using PROTO for K — we'll see how long it lasts. I never use auto-complete and I don't mind typing shit out; I'm just trying to minimize repetitive line noise for ready readability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment