library works & start using it. 2. Debug a library when something goes wrong. 3. Integrate a library with their workflow. 4. BONUS: Submit a patch to the library.
THE LIB. Make your code readable. ◦ "Common conventions" ▪ Idiomatic.js ▪ Crockford ▪ Google ▪ Stoyan Stefanov ◦ Descriptive variable names Make your code debuggable. ◦ On *all* platforms.
l = a.length; for (var i = 0; i < l; i++) { var item = a[i]; if (item.length == 2) { r += "0" + item; } else { r += item; } } function login(a, b) { b = b || { perms: '' }; PhoneGap.exec(function(e) { FB.Auth.setSession(e.session, 'connected'); if (a) a(e); }, null, 'com.phonegap.facebook.Connect', 'login', b. perms.split(',') ); }
is the single most important quality of a piece of code. Semicolons aid readability by eliminating ambiguity and ensuring that nobody ever has to spend even a second figuring out whether your code will do what it looks like it will do." "Relying on implicit insertion can cause subtle, hard to debug problems. Don't do it. You're better than that." Google Style Guide Jason Kester
The core team aren't the only developers looking at the code. (But they might be if that's the philosophy.) Don't use your library code to show off how well you know the idiosyncrasies of a language.
$$ = function(element, selector){ var found; if (element === document && idSelectorRE.test(selector)) { found = element.getElementById(RegExp.$1); return found && [found] || []; } else if (classSelectorRE.test(selector)) { return slice.call(element.getElementsByClassName(RegExp.$1)); } else if (tagSelectorRE.test(selector)) { return slice.call(element.getElementsByTagName(selector)); } else { return slice.call(attemptQuerySelectorAll(element, selector)); } } If you have the choice between two styles and one is more readable, choose that one.
WORKFLOW. Try your code with popular JS build tools • JSHint • Closure Compiler / UglifyJS • Grunt If it requires options, specify them or inline them into the code.