Like any good programmer, I’d like to stay on top of any changes planned for programming languages that I use (or scripting languages). So when I heard about EcmaScript 5th Edition (near final draft) being released, I wanted to get all of the juicy details on what to expect. As it turns out, this hasn’t been documented really well yet: so I did the better thing and read the draft.
There are some really exciting things to come, some of the biggest being to the foundation Object object’s functions which will allow turning off Enumeration on properties, making “read only” properties, etc. I’ve noticed a lot of this has come from Mozilla’s innovation and also I see some similarities to PrototypeJS’s modifications to prototypes.
(more…)
There isn’t a huge conspiracy to hide what closures mean to the power of JavaScript, but the principles can be easily understood.
A closure is actually more liberating than the name implies. It opens the door to new possibilities by passing variables between lower-level functions.
Take for example, a very simple closure:
var ourFunction =
function() {
var ourFunction2 =
function() { alert
(ourVar
);
};
var ourVar =
"A simple JavaScript closure.";
ourFunction2();
};
As you can see, the ourVar variable is available to ourFunction2 despite ourVar being defined in the scope of ourFunction (locally). Even if ourFunction2 wasn’t defined inside of ourFunction, we’d still have access to ourVar. Similarly, if ourVar was a parameter of ourFunction, we’d still have access to it within ourFunction2.
(more…)