JavaScriptのベストプラクティス大会 jsEdu

詳細は"10 Free Copies of “JavaScript Patterns” from O’Reilly Books | Nettuts+" http://net.tutsplus.com/freebies/books/10-free-copies-of-javascript-patterns-from-oreilly-books/ 要は #jsEdu つけてJavaScriptのTips投稿してね。の検索メモ。 追記:一部取り出して日本語にしてみました。 続きを読む
13
前へ 1 ・・ 14 15
Alfredo Serafini @seralf

use closure, but don't close yourself on overusing anonymous functions! :-) #jsEdu

2010-10-14 18:46:34
ripter001 💎 @ripter001

Instead 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:02
Ryan Gillett @ryangillett

keep a copy of IE6, it's good for nothing except breaking on any minor/obscure JS error #jsEdu

2010-10-14 19:45:34
ripter001 💎 @ripter001

Javascript 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:02
Nick Fitzsimons @NickFitz

Always 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:37
KAISSER Cherki @kaissercherki

Quick Tip: Dissecting jQuery – Text . #jsEdu

2010-10-14 21:08:42
@andrezyk

JavaScript forms best-practice - Reference To Form Input: document.forms["formname"].elements["inputname"] - #jsEdu

2010-10-14 22:29:06
Russell Uresti @RussellUresti

When 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:04
Szymon Pilkowski @ard

Nice way to randomize an array: [1,2,3].sort( function() { return (Math.round(Math.random())-0.5) } ) #jsEdu

2010-10-15 08:53:12
Szymon Pilkowski @ard

Object.prototype.x creates global variable x (because window instanceof Object === true) #jsEdu

2010-10-15 08:45:53
BartAttack @outsbart

You 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:51
Mike V @thewebvy

Do 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:02
PlNG @Shamamouse

Shorter 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:20
patgannon @patgannon

In 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:00
netzzwerg @netzzwerg

document.getElementsByTagName('*').length for number of dom nodes #jsEdu

2010-10-15 01:00:28
Atsushi Takayama @edvakf

#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
前へ 1 ・・ 14 15