Revisiting the code after some time has passed requires: • Time to relearn and understand the problem • Time to understand the code that is supposed to solve the problem As the application matures, many other things happen that require your code to b…
Free and open source tools for doc generation: the JSDoc Toolkit (http://code.google.com/p/jsdoc-toolkit/) and YUIDoc (http://yuilibrary.com/projects/yuidoc). Process of generating API documentation • Writing specially formatted code blocks • Running…
Document all functions, their arguments and return values, and also any interesting or unusual algorithm or technique. Think of the comments as hints to the future readers of the code; the readers need to understand what your code does without readin…
转自:https://dave.cheney.net/practical-go/presentations/qcon-china.html?from=timeline   1. Guiding principles If I’m going to talk about best practices in any programming language I need some way to define what I mean by best. If you came to my keynote…
7.1 Singleton The idea of the singleton pattern is to have only one instance of a specific class. This means that the second time you use the same class to create a new object, you should get the same object that was created the first time. var obj =…
Chaining Pattern - Call methods on an object one after the other without assigning the return values of the previous operations to variables and without having to split your calls on multiple lines. var obj = { value: 1, increment: function () { this…
Drawbacks of the namespacing pattern • Reliance on a single global variable to be the application’s global. In the namespacing pattern, there is no way to have two versions of the same application or library run on the same page, because they both ne…
All object members are public in JavaScript. var myobj = { myprop : 1, getProp : function() { return this.myprop; } }; console.log(myobj.myprop); // `myprop` is publicly accessible console.log(myobj.getProp()); // getProp() is public too The same is…
It’s a good idea to declare the modules your code relies on at the top of your function or module. The declaration involves creating only a local variable and pointing to the desired module. var myFunction = function() { // dependencies var event = Y…
global namespace object // global object var MYAPP = {}; // constructors MYAPP.Parent = function() { }; MYAPP.Child = function() { }; // a variable MYAPP.some_var = 1; // an object container MYAPP.modules = {}; // nested objects MYAPP.modules.module1…