Last active
August 29, 2015 13:57
-
-
Save joseph/9771701 to your computer and use it in GitHub Desktop.
JS class pattern [4]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 usingPROTO
forK
— 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.