PDA

View Full Version : repeated get references, should I save the reference?



derek.adair
31 Oct 2012, 11:16 AM
Hello there fellow Ext'ers!

I have a simple best practices question that's a little bit over my head at the moment. In jQuery it's a good idea to save the reference to a jQuery object in order keep from initializing / running the dom selector magic every time you reference a jQuery object.

like so:

var $myObj = $("#someSelector");

Now, i'm 90% sure I should do the same in ExtJS, but I wanted to know if there was anything dangerous or wrong in the way I would like to do this.

I have a reference:


{ ref: 'userList', selector: 'usertab userlist' }

That I use repeatedly like so...


this.getUserList().doSomething()
this.getUserList().doSomething()
this.getUserList().doSomething()
this.getUserList().doSomething()
this.getUserList().doSomething()

Is it a good idea to do...


var $userList = this.getUserList() ?

James Goddard
31 Oct 2012, 11:29 AM
It's always better to save the result of a function if you are going to use it multiple times.