我对模块设计模式的最佳实践有疑问.下面的代码是我们编写一些组件的方式的一个例子(我们使用ExtJs,但这不应该太重要).我们构建了很多这样的组件,我知道这与最佳实践完全不符.有任何想法清理代码?
Ext.ns("TEAM.COMPONENT");
function Foo() {
// Private vars
var privateNumber=0, myButton, privateInternalObject;
var numberField = new Ext.form.NumberField({
label : 'A NumberField!',
listeners : {
'change' : function(theTextField, newVal, oldVal) {
console.log("You changed: " + oldVal + " to: " + newVal);
}
}
});
// Some private methods
function changeNumField(someNumber) {
numberField.setValue(someNumber);
}
// Some public methods
this.publicFunctionSetNumToSomething() {
changeNumField(privateNumber);
}
/**
* Initializes Foo
*/
function init() {
// Do some init stuff with variables & components
myButton = …Run Code Online (Sandbox Code Playgroud)