0

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.

Steve
  • 4,534
  • 9
  • 52
  • 110

4 Answers4

5

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.

Pointy
  • 405,095
  • 59
  • 585
  • 614
1

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

1

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.

David Hellsing
  • 106,495
  • 44
  • 176
  • 212
  • I think it's safe to assume that the **js** display attribute is used for JS :P – tckmn Dec 05 '13 at 23:15
  • @Doorknob maybe, but the entire question is based on a false assumption that the code is javascript. It might as well be SEO-bogus HTML or microformats, you can’t tell for sure. – David Hellsing Dec 05 '13 at 23:16
1

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.

Community
  • 1
  • 1
Max Truxa
  • 3,308
  • 25
  • 38