1. #21
    Sencha - Community Support Team mschwartz's Avatar
    Join Date
    Nov 2008
    Location
    San Diego, Peoples' Republic of California
    Posts
    2,053
    Vote Rating
    17
    mschwartz will become famous soon enough mschwartz will become famous soon enough

      0  

    Default


    Code:
    $ nodejs test.js
    Elapsed: 879
    Elapsed: 925
    Looks like using local variable me vs. this is a 6% performance hit in chrome.

  2. #22
    Ext JS Premium Member yyjia's Avatar
    Join Date
    Oct 2008
    Location
    Greater Boston Area
    Posts
    89
    Vote Rating
    0
    yyjia is on a distinguished road

      0  

    Default


    Hi Mschwartz,

    This is interesting. I run your code in both Firefox 3.6.17 and IE 9 on my 32 bit Windows 7 platform. So far, what I observed is, in Firefox, the second Elapsed value is always around 10% less than first one. In IE 9, the second Elapsed value is always less than the first one. But, it is just around 2~3% less.

    I think it will be interesting to extend your testing code and do further statistical analysis.

    Yiyu Jia
    Thanks and regards,

    Yiyu Jia

  3. #23
    Ext JS Premium Member yyjia's Avatar
    Join Date
    Oct 2008
    Location
    Greater Boston Area
    Posts
    89
    Vote Rating
    0
    yyjia is on a distinguished road

      0  

    Default


    The testing result suggests me to use local variable instead of "this". I guess the difference comes from the difference of "local variable" and "this", which is in a outer scope. Who can give us insightful reason from Javascript engine?
    Thanks and regards,

    Yiyu Jia

  4. #24
    Ext JS Premium Member Steffen Hiller's Avatar
    Join Date
    Mar 2008
    Posts
    770
    Vote Rating
    28
    Steffen Hiller will become famous soon enough Steffen Hiller will become famous soon enough

      0  

    Default


    What's the latest opinion on this (ha),
    or let's say what's the rule to use "var me = this"?

    In ST2's code it's used a lot (380 times).

    What do you tell somebody that's learning JavaScript/ST/Ext?

  5. #25
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,073
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    It's purely for minification. The other use of it is for scope management like if you have a function within another function and you have var me = this outside the inner function then you can use the me variable within that inner function

    Code:
    function outerFunction() {
        var me = this;
    
        function innerFunction() {
            //access to me here!
        }
    }
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  6. #26
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,325
    Vote Rating
    114
    LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light

      0  

    Default


    Yahoo is also using this technique... pun intended

    ...except they assign this to self, not me.

    var self = this;

  7. #27
    Ext JS Premium Member Steffen Hiller's Avatar
    Join Date
    Mar 2008
    Posts
    770
    Vote Rating
    28
    Steffen Hiller will become famous soon enough Steffen Hiller will become famous soon enough

      0  

    Default


    I only use it where it comes handy for scope stuff.

    If I would also try to keep byte size in mind,
    according to evant's example (http://www.sencha.com/forum/showthre...l=1#post597272),
    I'd need to count the use of "this" after each modification within a function and decide to use it if it has more than 4 "this" keywords, since it's only beneficial then?

  8. #28
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    37,073
    Vote Rating
    854
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    Quote Originally Posted by LesJ View Post
    Yahoo is also using this technique... pun intended

    ...except they assign this to self, not me.

    var self = this;
    self, me, supercalifragilisticexpialidocious... doesn't matter what you name it, it will minify into a small variable like a or k or whatever the minifier can
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  9. #29
    Touch Premium Member
    Join Date
    Nov 2010
    Location
    Chicago
    Posts
    1,325
    Vote Rating
    114
    LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light LesJ is a glorious beacon of light

      0  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    self, me, supercalifragilisticexpialidocious... doesn't matter what you name it, it will minify into a small variable like a or k or whatever the minifier can
    Exactly, some people assign var that = this... I hate that

  10. #30
    Ext JS Premium Member yyjia's Avatar
    Join Date
    Oct 2008
    Location
    Greater Boston Area
    Posts
    89
    Vote Rating
    0
    yyjia is on a distinguished road

      0  

    Default


    search key words "javascript scope chain performance optimization". You will see right discussion though some of them are out of time already. The key here is "scope chain". Please update here if you know something has been changed in latest javascript engines.
    Thanks and regards,

    Yiyu Jia

Similar Threads

  1. Replies: 5
    Last Post: 2 Jan 2014, 9:08 AM
  2. Replies: 4
    Last Post: 31 Mar 2011, 9:04 AM
  3. Replies: 3
    Last Post: 28 Oct 2009, 6:38 AM
  4. replace the "south" with the "new Ext.StatusBar" in "layout:'border'"
    By ealpha in forum Ext 2.x: Help & Discussion
    Replies: 1
    Last Post: 18 May 2008, 8:28 PM

Thread Participants: 14