Javascriptメモ

greasemonkey実行時のエラーをFirebugで捕捉する

Firebugの「コンソール」タブ右側の「オプション」から 「Chrome のエラーを表示」 にチェックを入れる。

aa 内の子要素として bb を挿入

// 末尾に
aa.insertBefore( bb, null );
// 先頭に
aa.insertBefore( bb, aa.firstChild );

正規表現

// 基本
str.match( /~/ );

// マッチした場合に処理
if( str.match( /~/ ) ){
  // マッチした場合の処理
}

// 括弧で参照
str.match( /(..)(...)/ );
foo = RegExp.$1;
bar = RegExp.$2;

イベントドリブンな処理

// 関数を作成
var foo = function (){
  ;
}
// イベントに対応付け
window.addEventListener( "load", foo, true );
参考: 第6回 イベントハンドラから脱却しよう:ITpro
2008/11/18