This is perfect Saki, thank you. --Wregen 02:48, 28 August 2007 (CDT)
Contents |
Thank you. I tried to understand Crockford's examples[1]. and I got a basic understanding for the private, privileged, public concept but the way it was formatted was so daunting. I just couldn't figure it out. Nor foresee myself remembering the pattern for future applications. (The information about this was overwhelming at first[2].)
The way you laid out how objects are formated and where and how each component becomes private/public/privileged was perfect. I'll use that model from now on.
Thanks. Suki 01:19, 4 September 2007 (CDT)
I've tried this on Ext 2.0. Adding a few change finally it ran.
Ext 1.1:
btn1 = new Ext.Button('btn1-ct', {
text: this.btn1Text,
handler: btn1Handler
});
Ext 2.0:
btn1 = new Ext.Button({
text: this.btn1Text,
handler: btn1Handler,
applyTo:'btn1-ct'
});
I wonder if this is the trully recommended method for migrating to Ext 2.0, but I try to post this tip.
There's also a modified version that allows access to public variables and functions also to private functions:
myNameSpace.app = function() {
// private
var myVar;
var myFunc=function() { alert pub.myPub()+pub.myPubVar };
// public
pub={
myPubVar: 1,
myFun: function() { return 5 }
}
return pub;
}();
mikeH 21:16, 13 February 2008 (CET)
Douglas Crockford also wrote another page: Private Members in JavaScript[3], which begins: "Javascript is the world's most misunderstood programming language ..." This page, and the hotlinks leading from it, are well worth the reading.
In fact, Douglas' very extensive "JavaScript" section[4] on his web site is a recipe for an afternoon (or several afternoons...) very well spent.