【发布时间】:2011-09-22 17:39:18
【问题描述】:
有一个老技巧 (that I learned on SO) 将构造函数作为函数调用,即忘记 new 关键字。下面的,或者类似的,它放在顶部的每个构造函数中。
if (!(this instanceof arguments.callee)) {
throw Error("Constructor called as a function");
}
当您需要"use strict"; 时,有哪些替代方案?
可以保留其通用性吗?还是我们必须使用构造函数的名称来代替arguments.callee?
【问题讨论】:
标签: javascript constructor arguments strict-mode