2016-02-19 40 views

回答

2

當你調用h,其上下文this指的是輸入錯誤。您可以通過將其綁定到document來解決此問題。

var h = document.createElement.bind(document) 

alert可稱爲-是,這樣的範圍不發生變化的時候,你的別名它。

+0

爲什麼上下文在alert中保持不變? –

+0

因爲默認範圍是'window'; 'x'與'window.x'相同; 'h'也是'window.h',但需要是'document.h'。 – Mathletics

+0

輝煌。這讓我很困惑。 –