javasciptでのスコーピングに関する問題があります。私は "new"キーワードを使って問題なく新しいオブジェクトを作成しようとしました。コードはこのJavascript:新しいキーワードコンストラクタを使用した字句スコープの問題
"use strict";
function Person() {
this.name = "john doe";
console.log(this.name);
}
Var foo = new Person()
のように見える私は名前の変数のスコープは、内部機能
"use strict";
function Person() {
this.name = "john doe";
Function speak() {
console.log("my name is" + this.name);
}
speak();
}
var foo = new Person();
//error: "cannot read property 'name' of undefined"
内不定となり、内部機能を追加しようとしたとき、私は遭遇した問題がある誰かがあると思われるものを説明することはできます問題?みんな
厳格モードで
重複質問のように見える:https://stackoverflow.com/questions/762011/whats-the-difference-between-using-let-and-var-to-declare -a-variable – RetroCoder
w3schoolsでも:https://www.w3schools.com/js/js_strict.asp – RetroCoder
[JavaScriptで「厳密に使用する」とは何か、その背後にある推論は何ですか?](https ://stackoverflow.com/questions/1335851/what-does-use-strict-do-in-javascript-and-what-is-the-reasoning-behind-it) – RetroCoder