Daily Archive for May 29th, 2008

ExtJS / Javascript - Deep Copy

We often need to do deep copies of Javascript objects so that we can modify the copy without it affecting the original. I have created the following clone function that does this quickly and easily; however, it does have limitations. If you clone an instance of, lets say, an Ext.Panel, Javascript’s instanceof function will fail to recognize it as an instance of Ext.Panel. From what I can gather, this is because the Javascript engine has some kind of internal reference to an object’s constructor and instanceof doesn’t actually look at the constructor we are able to modify… lets look at an example so it is more clear:

Continue reading ‘ExtJS / Javascript - Deep Copy’

ExtJS Performance - Element click events

A question appeared on the ExtJS forums today regarding how to bind event listeners on multiple links that are generated from the server.  Bind an event listener to each link, right?  Wrong!  This is wrong in the sense that it wastes system resources and is unnecessary.  Can you imagine how much resources TreePanel would take up if it bound a click listener on every single node element!? Oh wait… that’s probably what you though it did :-).  But it doesn’t. 
Continue reading ‘ExtJS Performance - Element click events’