JavaScriptのベストプラクティス大会 jsEdu
Use anonymous functions in setTimeout and setInterval instead of named functions or strings for more flexible scope. #jsEdu #javascript
2010-10-13 00:22:55Wrap your JavaScript code in a function to localize variables. #jsEdu
2010-10-13 00:23:12Try not to use myVar.length as the conditional statement in for loops, because it will need to be calculated every time. #jsEdu
2010-10-13 00:23:39Use the Object Literal pattern to organize your JavaScript code. var obj ={method:function(){},method:function(){}}; #jsEdu
2010-10-13 00:25:00Variables in javascript either have global scope or function scope, always use the 'var' keyword to control this #jsEdu
2010-10-13 00:25:12Use Object.prototype.hasOwnProperty.call(yourObject, i) in for-in loop. You can prevent bugs with extending built-in types. #jsEdu
2010-10-13 00:26:26JS Best Practices: comment your code! You'll appreciate this later. Use === rather than ==. And use external files. #jsEdu cc @nettuts
2010-10-13 00:27:24Specify the radix when calling parseInt() and parseFloat(). Otherwise, you may experience inconsistent results. #jsEdu
2010-10-13 00:29:19In JavaScript, always declare your variables with "var" to avoid scoping confusion. #jsEdu
2010-10-13 00:29:56Shorthands is better. "var name = []" is more simple than "var name = new array ()" #jsEdu
2010-10-13 00:34:21Use a document fragment to append multiple elements to the page at once. One reflow rather than many = a big performance boost #jsEdu
2010-10-13 00:34:27The DOM is slow. Limit your interaction with it (especially if your changes require a repaint or reflow). #jsEdu
2010-10-13 00:35:34Always declare your variables outside of the for statement #jsEdu
2010-10-13 00:37:04Use event delegation instead of assigning event handlers to multiple elements. #jsEdu
2010-10-13 00:37:21Wrap your code in an auto-executing function to localize your variables.( function( $ ) { /* Code */ } )( jQuery ); #jsEdu
2010-10-13 00:39:22@junihh it might be quicker to type, but it's less legible #jsEdu
2010-10-13 00:40:04More performance ?? don't forget this: "var array_total = arrayname.length" to use it with "for". #jsEdu
2010-10-13 00:41:42Always avoid using uppercase letters in variable/object/function names. Javascript is CASE SENSITIVE! #jsEdu
2010-10-13 00:43:21getElementbyID will also match elements by name in IE. be careful about that to avoid compatibility problems #jsEdu
2010-10-13 00:43:57Objects can be used as hash tables. obj["myMethod"](); is the same as obj.myMethod(). #jsEdu
2010-10-13 00:45:10Always use an object literal -- {} -- instead of the new Object() contructor. #jsEdu
2010-10-13 00:47:18Search for #jsEdu in twitter for a great collection of JavaScript best practices tips :-)
2010-10-13 00:47:41Sweet shortcuts: +operator converts to number, !! converts to boolean: var foo='42';console.log(typeof foo,typeof +foo,typeof !!foo); #jsEdu
2010-10-13 00:47:58Alway try to use CamelCased variables when writting Javascript #jsEdu
2010-10-13 00:48:34