Code Archive Skip to content Google About Google Privacy Terms
2009年01月19日18:15 カテゴリLightweight Languages javascript - block代わりのclosureとその問題 リハビリに手頃な問題だったので。 これ、実は「Java開発者のためのAjax実践開発入門」でも紹介されている書き方。 for 文と無名関数のイディオム - IT戦記 というわけで、これをすべて解決するのが for (var i = 0, len = list.length; i < len; i++) (function(node, i) { var text = node.textContent; node.onclick = function() { alert(text) }; })(list[i], i) なのだ。 ただし、コメント欄に残された問題が残る。 自分でも検証してみた。 n = : これ、デフォルトでは100万回にして
Closures Are Not Magic This page explains closures so that a programmer can understand them - using working JavaScript code. It is not for gurus nor functional programmers. Closures are not hard to understand once the core concept is grokked. However, they are impossible to understand by reading any academic papers or academically oriented information about them! This article is intended for prog
JavaScript には基本的にブロックスコープというものが存在しない。どうしてもブロックスコープを扱いたいときは function 式を使ったりする。 var a = 10; { var a = 20; print(a); // 20 } print(a); // 20 var a = 10; (function () { var a = 20; print(a); // 20 })(); print(a); // 10 だがやはりブロックスコープがあったほうが便利ということで JavaScript 1.7 では let 式、let 文、let 宣言が導入される。 var a = 10; let (a = 20) { print(a); // 20 } print(a); // 10 しかしこれでは対応するブラウザが Firefox 2 以降などに限られる。ところが、with 文とオブ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く