0
こんにちは私は初心者のJavaScriptを学んでいます。 2つのコンストラクターの違いは何ですか?Constructorの関数名とは何ですか?
function Animal(name) {
this.name = name;
this.walk = function walk(destination) { //here function has name 'walk'
console.log(this.name,'is walking to',destination);
};
}
と
function Animal(name) {
this.name = name;
this.walk = function (destination) { // but no function name
console.log(this.name,'is walking to',destination);
};
}
事前にありがとうございます!
関数に名前を付けると、デバッグに役立ちます。そうでなければ、彼らはほとんど同じように動作します。 –
また、 'walk'を再帰的に呼び出す場合、別の参照を保持しなくても、その関数を' walk'と呼ぶことができます。 – nils
関数式がコンストラクタ関数の内部にあるということは無関係です。 – Quentin