Thursday, April 24, 2008

javascript variable scope

The scope of a variable is the current function or, for variables declared outside a function, the current application.
Aassigning a value to an undeclared variable implicitly declares it as a global variable.

Each function is associated with its closure chain
A variable is undefined if cannot be found in the current closure chain,
and the access attemp will generate error.

The global function 'eval' uses current closure chain to evaluate the string.
If a function is still accessible, its function closure chain is still in memory.

Tuesday, April 22, 2008

Image flicker in IE6

This is due to IE 6 keeps check for the background image specified in css property everty time the element is moved over. Note that IE 5 or IE 7 do not have this problem.

A good post about this problem is at http://www.mister-pixel.com/

The solution is to add following javascript code inside the HEAD of the page:
try {
document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

This fix works only with Internet Explorer 6, Service Pack 1 or newer.
Also, the fix does not apply if you change the background image on :hover. It only prevents the flicker of the same background image, when changing other rules inside the :hover state. But you can still change the background position.