Why write `window[ “eval” ].call( window, data );`

前端 未结 2 1745
粉色の甜心
粉色の甜心 2021-01-17 22:49

Line 614 of jQuery 1.7rc1:

window[ \"eval\" ].call( window, data );

Why not simply write

eval.call( window, data );?

2条回答
  •  长发绾君心
    2021-01-17 23:13

    The answer is here: Decoding jQuery,

    Jim Driscoll found out that for more standards-respecting browsers, you could use eval.call(window,data), but for Chrome and IE, things are a bit different.

    Internet Explorer: It seems that IE uses window.execScript(data)

    Chrome: eval.call(window,data) breaks on Chrome, but window[ "eval" ].call( window, data) works on Chrome, and as well as other non-IE browsers, this is how the above workarounds based upon.

提交回复
热议问题