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
輝煌。這讓我很困惑。 –