0
非法调用时,如果我能写的Javascript遗漏的类型错误:引用使用document.createElement
var x = window.alert;
x("Hello"); //This works as expected.
为什么我不能够写相同的document.createElement
。
var h = document.createElement;
h("div"); //This line throws error
Uncaught TypeError: Illegal invocation
为什么上下文在alert中保持不变? –
因为默认范围是'window'; 'x'与'window.x'相同; 'h'也是'window.h',但需要是'document.h'。 – Mathletics
辉煌。这让我很困惑。 –