JavaScript variable scope question: to var, or not to var

Many thanks in advance. I'm working out of a schoolbook and they're using one function to call another which opens a window: function rtest(){ content='dans window'; oneWindow=open("","Window 1","width=450,height=290"); newWindow(oneWindow); } function newWindow(x){ x.document.close(); x.document.open(); x.document.write(content); x.document.close(); x.moveTo(20,

JavaScript变量范围问题:var,或不var

提前谢谢了。 我正在学习一本教科书,他们使用一个函数调用另一个函数打开一个窗口: function rtest(){ content='dans window'; oneWindow=open("","Window 1","width=450,height=290"); newWindow(oneWindow); } function newWindow(x){ x.document.close(); x.document.open(); x.document.write(content); x.document.close(); x.moveTo(20,20); x.focus(); } 所以一切工作正常,但我的问题是

Should I use window.variable or var?

We have a lot of setup JS code that defines panels, buttons, etc that will be used in many other JS files. Typically, we do something like: grid.js var myGrid = ..... combos.js var myCombo = ..... Then, in our application code, we: application.js function blah() { myGrid.someMethod() } someother.js function foo() { myCombo.someMethod(); myGrid.someMethod(); } So, should

我应该使用window.variable还是var?

我们有很多设置JS代码,它们定义了面板,按钮等,这些代码将用于许多其他JS文件。 通常情况下,我们做类似的事情 grid.js var myGrid = ..... combos.js var myCombo = ..... 然后,在我们的应用程序代码中,我们: 的application.js function blah() { myGrid.someMethod() } someother.js function foo() { myCombo.someMethod(); myGrid.someMethod(); } 所以,我们应该使用var myGrid还是更好地使

Simple Javascript question

When I click on the button, the first time, everything works fine, but the second time, nothing happens. Why is that?