デモクラスのtypescriptコードのコンパイル済みバージョンにいくつかの変更を適用することによって、次のコードを取得しました。私が得たIIFEを除去した後括弧で囲まれた関数(IIFE)の新しい演算子
function f() {
function Demo() {
console.log("Inside constructor");
}
return Demo;
}
var Demo = (f)();
console.log("Creating instance");
var demo = new Demo();
// Output
// Creating instance
// Inside constructor
、最初のケースで
function f() {
function Demo() {
console.log("Inside constructor");
}
return Demo;
}
var Demo = f;
console.log("Creating instance");
var demo = new Demo();
// Output
// Creating instance
、デモの起動時に実行さコンストラクタ。 2番目のケースでは、Demoを呼び出すとコンストラクターが実行されませんでした。各ケースでnew
オペレータはどのように動作しますか?
それは 'new'キーワードに関するものではありません、それはVARデモ=(f)は()'についてです – Rayon