JavaScriptのベストプラクティス大会 jsEdu
use closure, but don't close yourself on overusing anonymous functions! :-) #jsEdu
2010-10-14 18:46:34Instead of if( i % 2 ) to detect even/odd, use if( i & 1 ) It's faster because of the bit operator. #jsEdu
2010-10-14 19:38:02keep a copy of IE6, it's good for nothing except breaking on any minor/obscure JS error #jsEdu
2010-10-14 19:45:34Javascript is function scoped, not block scoped. Declaring variables inside loops is the same as declaring them outside the loop. #jsEdu
2010-10-14 19:48:02Always specify the optional radix for parseInt(val, radix) in case of leading 0s: parseInt("010") == 8, but parseInt("010", 10) == 10 #jsEdu
2010-10-14 19:54:37JavaScript forms best-practice - Reference To Form Input: document.forms["formname"].elements["inputname"] - #jsEdu
2010-10-14 22:29:06When searching for a word in a string, .test() is faster than .search(), but .indexOf() is faster than .test() (except in Chrome). #jsEdu
2010-10-14 23:39:04Nice way to randomize an array: [1,2,3].sort( function() { return (Math.round(Math.random())-0.5) } ) #jsEdu
2010-10-15 08:53:12Object.prototype.x creates global variable x (because window instanceof Object === true) #jsEdu
2010-10-15 08:45:53You can append an empty string to a variabile (or a literal) to quickly convert it into a string: alert(typeof(12345 + '')); #jsEdu
2010-10-15 05:04:51Do more w/less, cache your DOM elements in jQuery the first time you operate on them { var el = $('#a').hide(); $(el).show(); } #jsEdu
2010-10-15 03:37:02Shorter than parseInt: If a string only contains a number, multiply it by one to change the type from string to number. #jsEdu
2010-10-15 03:22:20In JS, the following values are equivalent to false in an 'if' statement: null, undefined, "", 0, NaN (and false) /via @elijahmanor #jsEdu
2010-10-15 01:43:00document.getElementsByTagName('*').length for number of dom nodes #jsEdu
2010-10-15 01:00:28#jsEdu sort() is not stable by spec (Chrome and Opera's impl. too). Write your custom sort() for table sorting etc.
2010-10-15 00:18:22