[英]Whats wrong with this code in jsfiddle
var x = "window.Something";
alert(window.x)
when i try this code in jsfiddle http://jsfiddle.net/XJEGU/ , it alerts undefined. 当我在jsfiddle http://jsfiddle.net/XJEGU/中尝试此代码时,它会提示未定义。 While when i run this code in my browser, it works fine, can anybody tell what jsfiddle does with this code for such behavior. 当我在浏览器中运行此代码时,它工作正常,任何人都可以告诉jsfiddle这个行为的代码。
JSFiddle wraps code in a function. JSFiddle在函数中包装代码。 This means that x
is scoped locally to that function. 这意味着x
在本地作用于该函数。
If you are trying to embed a variable to the window. 如果您尝试将变量嵌入窗口。 You can use this http://jsfiddle.net/XJEGU/3/ 你可以使用这个http://jsfiddle.net/XJEGU/3/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.