Results 1 to 2 of 2

Thread: repeated get references, should I save the reference?

  1. #1
    Sencha User
    Join Date
    May 2011
    Posts
    1
    Vote Rating
    0
      0  

    Default repeated get references, should I save the reference?

    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:
    Code:
    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:

    Code:
    { ref: 'userList', selector: 'usertab userlist' }
    That I use repeatedly like so...

    Code:
    this.getUserList().doSomething()
    this.getUserList().doSomething()
    this.getUserList().doSomething()
    this.getUserList().doSomething()
    this.getUserList().doSomething()
    Is it a good idea to do...

    Code:
    var $userList = this.getUserList()
    ?

  2. #2
    Ext JS Premium Member
    Join Date
    Nov 2009
    Location
    St Louis,MO
    Posts
    267
    Answers
    20
    Vote Rating
    18
      0  

    Default

    It's always better to save the result of a function if you are going to use it multiple times.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •