Steve
Steve

Reputation: 4908

What is $this here in this JavaScript?

I'm looking at JavaScript that produces:

enter image description here

The related code is

enter image description here

My question is, what does $this refer to? Just the keyword "this" I understand, but $this? There doesn't seem to be any jQuery around.

Thanks for any illumination.

Upvotes: 0

Views: 310

Answers (4)

Max Truxa
Max Truxa

Reputation: 3478

Pointy is right for this specific case.

To clear up the confusion about $ in JavaScript:

In JavaScript the dollar sign ($) in variable names is treated like a-z, A-Z and underscore (_).

The variable you are looking at, could have been named anything else. $this is no special JS keyword. The developers of jstemplate could have named it foo if they wanted to. Or like they did, something similar to this, like _this or self.

Upvotes: 1

David Hellsing
David Hellsing

Reputation: 108500

That is not javascript, it’s HTML.

What you see is a custom element property called jsdisplay that has the value of $this.something. What it actually does is very hard to give an exact answer to, but as some other pointed out it’s probably used internally in google templating.

Upvotes: 1

Coder101101010
Coder101101010

Reputation: 144

It appears to be prefixed with $ due to using the Google JSTemplate API.

More information here: http://code.google.com/p/google-jstemplate/wiki/HowToUseJsTemplate

Upvotes: 1

Pointy
Pointy

Reputation: 413826

It has to do with the Google "jstemplate" mechanism.

From that page:

$this: $this refers to the JsEvalContext data object used in processing the current node. So in the above example we could substitute $this.end for end without changing the meaning of the jscontent expression. This may not seem like a very useful thing to do in this case, but there are other cases in which $this is necessary. If the JsEvalContext contains a value such as a string or a number rather than an object with named properties, there is no way to retrieve the value using object-property notation, and so we need $this to access the value.

Upvotes: 5

Related Questions