JavaScript の this は関数定義時に決まるのではなく、関数の呼び出し方によって変わることを解説します。
![What's this -- いまさら聞けない JavaScript の this](https://cdn-ak-scissors.b.st-hatena.com/image/square/846fd4428f804d71a5798339fb8b93a048cf8a82/height=288;version=1;width=512/https%3A%2F%2Ffiles.speakerdeck.com%2Fpresentations%2F70a3d8004390013257d62242f16da36d%2Fslide_0.jpg%3F3823232)
JavaScript の this は関数定義時に決まるのではなく、関数の呼び出し方によって変わることを解説します。
JavaScript’s this: how it works, where it can trip you up [2017-12-06] Follow-up post: “A different way of understanding `this` in JavaScript” In JavaScript, the special variable this is relatively complicated, because it is available everywhere, not just in object-oriented settings. This blog post explains how this works and where it can cause problems, concluding with best practices. To understa
<<前回「CoffeeScriptって何?」へ<< CoffeScriptを3時間で理解するための10のポイントのうち、ポイント1から3までを解説します。ポイント1は「CoffeeScriptはコンパイルで即時関数に変換される」こと、ポイント2は「変数は自動的に宣言される」こと、ポイント3は「リテラルで豊かな表現を可能に」したことです。 POINT1 CoffeeScriptはコンパイルで即時関数に変換される ★「即時関数」でグローバル変数を作らない ★JavaScriptのstrictモードにも対応 CoffeeScriptで記述されたコードをコンパイルすると、JavaScriptのコードは、(function() {...}).call(this);でラップされた状態で出力されます(リスト7)*1。奇異にも見える書き方ですが、実は、JavaScriptの世界では定石とも言える書き方の一
// よく見かける即時関数 (function () { // ... })(); // underscore.jsの即時関数 (function () { // ... }).call(this); underscore.jsの即時関数 underscore.jsは何故callで関数を呼び出しているのかというと JavaScripstのstrictモードでは関数内のthisがundefinedになる 'use strict'; // よく見かける即時関数 (function () { console.log(this); // undefined })(); // underscore.jsの即時関数 (function () { console.log(this); // 即時関数の外のthisが表示される }).call(this); strictモードでない場合はどちらの記述でも関
Editor’s note: This article was updated by our editorial team on January 18, 2023. It has been modified to include recent sources and to align with our current editorial standards. Today, JavaScript is at the core of virtually all modern web applications. That’s why JavaScript issues, and finding the mistakes that cause them, are at the forefront for web developers. Powerful JavaScript-based libra
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く