On Sun, 02 Jan 2011 23:07:14 +0100, Garrett Smith <[email protected]>
wrote:
On 1/2/11, Lasse Reichstein <[email protected]> wrote:
It's redundant at best. At worst it can lead to a small slowdown.
The "this" operator is special and will always refer to the same value
during a call, and that value is (in ES3) known to be an object.
IIRC, old versions of IE had a miniscule, negligible improvement with
aliasing a local variable.
(`this` is a keyword, not an operator, BTW).
My bad. I was confuzing it with something else.
No nullary oprators than :(.
That means that usages of "this" can omit some checks that a variable
use would require (e.g. "this.method()" doesn't need to check whether
"this" refers to a primitive value that needs to be promoted to an
object).
Is this optimization limited to non-strict code?
Yes. In strict code, "this" can refer to a primitive value, including null
and undefined, so that optimization is off the table.
It's still known that "this" can't be captured by closures, and it's not
mutable.
/L
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]