Whats wrong with this code in jsfiddle

旧城冷巷雨未停 提交于 2019-12-11 03:13:11

问题


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 anybody tell what jsfiddle does with this code for such behavior.


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/6971543/whats-wrong-with-this-code-in-jsfiddle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!