I have been working on web project for past 4 months. To optimise the code performance we have used a pattern. My doubt is, does it actually boost performance or not?
when ever we have to use this object we assign it to a local variable, and use that.
function someFunction()
{
var thisObject = this;
//use thisObject in all following the code.
}
the assumption here is that, assigning this object to a local stack variable will boost the performance.
I have not seen this type of coding anywhere so doubt if it is of no use.
EDIT: I know that assigning this object to local variable is done for preserving object, but that is not our case.
While this is a common practice in Javascript it’s not done for performance reasons. The saving of the
thisobject in another named local is usually done to preserve the value ofthisacross callbacks which are defined within the function.Whether or not
thisObject === thisevaluates to true will depend on how it’s called