ドットインストール代表のライフハックブログ
JavaScriptプログラミングのTOPへ JavaScriptで,グローバル変数が存在するかどうか判定するための3つの方法。 3つのうち1つはよく使う。 残りの2つは,特殊な状況(WSHとの使い分けなど)で役立つ。 (1)「in window」 を使う 常套手段。 特定のオブジェクトが特定のプロパティを持っているかどうかを判定するためには,inを使う。 下記は, 一つ目のボタンでグローバル変数をセットし 二つ目のボタンでその存在判定を行なう というコード。 <input type="button" value="グローバル変数をセット" onClick="f()"> <input type="button" value="グローバル変数の定義状況を判定" onClick="g()"> <script language="JavaScript"> function f() { // グロ
JavaScriptで配列のクローンを作成しようとして、悩んでいる方もいらっしゃるようですが、 以下のように、for ループや再帰なコードを手書きする必要はなくて、Array.concat() で配列のクローンは作成できます。 Array.prototype.clone = function(){ return Array.apply(null,this) } Array.prototype.clone = function() { if ( this[0].constructor == Array ) { var ar, n; ar = new Array( this.length ); for ( n = 0; n < ar.length; n++ ) { ar[n] = this[n].clone(); } return ar; } return Array.apply( null,
Kanasan.JS JavaScript 第 5 版読書会 #1 にて delete 演算子の動作が話題に上ったそうです。そこで、それについてちょっとまとめてみようかと思い立ったはいいものの、ずるずると引き伸ばしているうちに年を越してしました。しかし、読書会 #2 の開催も決まり、もうこれ以上引き伸ばしているといつまでたっても書けなさそうなので、いい加減腹をくくって個人的にまとめてみようと思います。 JavaScript の変数 delete 演算子の対象 変数に対する delete 演算子 削除できるプロパティとできないプロパティ 変数の属性 delete 演算子の返り値 JavaScript の変数 delete 演算子の話に移る前に、変数とは何なのかおさらいしておきましょう。JavaScript において、変数とはプロパティの別名です。といっても、すべてのプロパティを変数というわけ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く