Created
March 30, 2011 14:53
-
-
Save phiggins42/894544 to your computer and use it in GitHub Desktop.
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
dojo.provide("Foo"); // always first | |
dojo.require("All.Your.Code.Are"); // always second | |
dojo.require("Belong.To.Us"); | |
(function(d){ // optional wrapper / privatizer / closure | |
// privates for this module | |
var yep = true, | |
nope = false, | |
helperUpper = function(str){ | |
return str.toUpperCase() | |
} | |
; | |
// declarations | |
dojo.declare("MyTHing", [inheritanceChain], { | |
member1: "Public members listed first in declcartion", | |
anumber: 42, | |
etc: "and so on", | |
// private members, too: | |
_test: 1, | |
_test2: 3, | |
_test5: "etc", | |
// begin lifecycle overrides | |
postMixInProperties: function(){ | |
dojo.mixin(this, { something:"random" }); | |
this.connect(this.domNode, "click", "awesomeFunction"); | |
this.inherited(arguments); | |
}, | |
// and so on | |
// begin public class members | |
awesomeFunction: function(e){ | |
this.foobar = this.oneMore("time"); | |
}, | |
_privateHelperForAwesomeFunction: function(e){ | |
// should be immediately following the function it helps | |
}, | |
anotherAwesomePublicFunction: function(){}, | |
oneMore: function(arg){ | |
return helperUpper(arg); | |
}, | |
// unless it's super generic, then it goes at the bottom. | |
_count: function(f){ | |
} | |
}); | |
})(dojo); |
not with es3 ... which is everywhere. modern browsers you could use defineGetter et al and accomplish this, but I'm a pragmatist and also still have to support ie6 in most things, so it's more of a pipe dream.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
could you, for example, arrange it so that properties are private but you have public setters/getters? Or once the closure fires the variable is accessible but cannot be updated?