摘要:
bad code// BEFORE: 5 globals// Warning: antipattern// constructorsfunction Parent() {}function Child() {}// a variablevar some_var = 1;// some objectsvar module1 = {};module1.data = {a: 1, b: 2};var module2 = {};good code// AFTER: 1 global// global objectvar MYAPP = {};// constructorsMYAPP.Parent = 阅读全文
摘要:
This pattern is useful when your function has some initial preparatory work to do andit needs to do it only once.In such cases, the selfdefining function can update its own implementation.eg:var selfFunc = function () { console.log("First Initialization!"); selfFunc = function () { ... 阅读全文