Pages

Tuesday, December 24, 2013

JavaScript A Great Christmas Present

Christmas December 25, 2013, I received a great Christmas present.

How all this came to be, I had a JavaScript question. Searching the Web I didn't find a satisfactory answer, so I thought maybe someone who had written books on the topic would have an answer to my itching question.

A little history, I have been reading and writing JavaScript for a good number of years. I purchased Danny Goodman's JavaScript book JavaScript & DHTML Cookbook, 2nd Edition. A great book, as I have revisited again and again.

The Christmas present, I decided emailing Danny Goodman prompting him with my question. Within the same day, Danny Goodman responded with a great answer.

The post is to thank Danny Goodman and all who take the time helping others.


Danny Goodman's answer:

If I recall correctly, IE4 was the first browser to scope HTML element IDs as global variables. But it has become standard behavior in the mainstream browsers you’d be coding for these days (even going back some generations). Additionally, because the W3C HTML specifications say an element’s ID attribute should be unique within the document tree, I would expect the DOM behavior to continue onward.

In practice, it can make life difficult because it adds lots of objects to your global scope, and you have to be careful in how you name functions and objects intended for global scope to avoid name collisions (including collisions with globals specified in .js libraries you load into a document). On the other hand, it forces me to carefully consider adding _anything_ JavaScript to the global scope.

Danny

This post is for the purpose of my notes only.

“I invented nothing new. I simply assembled the discoveries of other men behind whom were centuries of work. Had I worked fifty or ten or even five years before, I would have failed. So it is with every new thing. Progress happens when all the factors that make for it are ready and then it is inevitable. To teach that a comparatively few men are responsible for the greatest forward steps of mankind is the worst sort of nonsense.”
Henry Ford

No comments:

Post a Comment