JavaScript has got this weird flaw, that if you forget to declare a
variable using the "var" keyword, the variable is declared in the
global scope instead of the current scope.

For example:

function foo() {
  bar = 1;
  var baz = 2;

// -> 1
// -> ReferenceError: baz is not defined

As a rule of thumb: Never declare a variable WITHOUT using the "var"
keyword. If you want to declare a global variable from inside a
function (which should be a sign you're doing something wrong), set it
as a property of the window object like so:

function foo() { = 1;

// -> 1

You should really get yourself a couple of books on JavaScript. I'd
strongly suggest getting:

- JavaScript: The Definitive Guide, Fifth Edition by David Flanagan,
- JavaScript: The Good Parts by Douglas Crockford

There's also a number of good books on Prototype out there:


Have fun!


You received this message because you are subscribed to the Google Groups 
"Prototype &" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

Reply via email to