开发者

Whats wrong with this code in jsfiddle

开发者 https://www.devze.com 2023-03-26 16:18 出处:网络
var x = \"window.Something\"; alert(window.x) when i try this code in jsfiddle http://jsfiddle.net/XJEGU/, it alerts undefined. While when i run this code in my browser, it works fine, can any开发者
var x = "window.Something";

alert(window.x)

when i try this code in jsfiddle http://jsfiddle.net/XJEGU/, it alerts undefined. While when i run this code in my browser, it works fine, can any开发者_StackOverflow社区body tell what jsfiddle does with this code for such behavior.


JSFiddle wraps code in a function. This means that x is scoped locally to that function.

Whats wrong with this code in jsfiddle


If you are trying to embed a variable to the window. You can use this http://jsfiddle.net/XJEGU/3/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号