第一个按预期工作:
var f1 = Object.getOwnPropertyNames(Function)
.forEach(function(element) {
console.log (typeof Function[element]);
}); // --> number, string, function
第二个输出错误消息:
var f2 = Object.getOwnPropertyNames(Function.prototype)
.forEach(function(element) {
console.log (typeof Function.prototype[element]);
});
TypeError:在严格模式下可能无法访问“调用者”、“被调用者”和“参数”属性
我怎样才能绕过它?
编辑:当前解决方法
var forbiddenOnStrictMode = ['caller', 'callee', 'arguments'];
var f2 = Object.getOwnPropertyNames(Function.prototype)
.forEach(function(element) {
if (forbiddenOnStrictMode.indexOf(element) == -1)
console.log (typeof Function.prototype[element]);
});
是否可以说节点编译器暂时忽略严格模式?