Phil Hassey - game dev blog
Phil Hassey as Syndrome
"Look, stores don't sell
costumes like this to just anyone."

language hangups

I’ve spent a bit of time fooling with javascript this past weekend. It really is okay, but I came across a few scoping gotcha. Scoping defaults to global, so

function fnc1() { a = 5; } fnc1(); alert("a: "+a);

Will show you that a is 5. I’m more used to languages that default to a local scope. To get variables into a local scope in javascript, this example should be written as:

b = null; function fnc2() { var b = 5; } fnc2(); alert("b: "+b);

Will show you that b is null – as expected.

Comments are closed.