[英]Strict mode alternatives to this instanceof arguments.callee
有一個老技巧( 我在SO上學到 )將一個構造函數作為函數調用,即忘記new
關鍵字。 以下,或類似的東西,它位於頂部的每個構造函數中。
if (!(this instanceof arguments.callee)) {
throw Error("Constructor called as a function");
}
當你需要"use strict";
時,有哪些選擇"use strict";
?
它的通用性質可以保留嗎? 或者我們是否必須使用構造函數的名稱來代替arguments.callee
?
不推薦使用arguments.callee
本身來支持命名函數表達式。 雖然我不一定同意這一舉動,但事情已經取得了進展。 因此,使用函數名替換arguments.callee
是嚴格模式下的唯一方法,也是非嚴格模式下的首選方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.