Sublime Forum

Unusual code decorating (JS)

#1

I’ve saved a .js file. In it I have the following function:

function ConstructorFunction(a){
this.x=1;
this.y=2;
this.z=3;
this.t=a;
}

Why are x and y a different colour than z and t?

0 Likes

#2

x and y were previously (useless) properties, like layerX and layerY :astonished:. But it’s probably more to do with them slipping through the net in the JavaScript.tmLanguage definition file.

I think it’s kinda cute that they stand out :sunglasses:

0 Likes

#3

But z and t are also properties.
I see what you’re saying though. If I put a this.layerX in there it also shows up coloured like the x and y properties. But layerX is a property of the event object coming from the DOM from a browser. The problem is, there is nothing special about these properties in the function as defined. Nothing different from z or t. I find it strange that some properties should be highlighted differently than others. Then again, I guess it’s good to know if you’re using a property that has relevance to the DOM.

0 Likes

#4

I think you’re crediting ST with too much intelligence :wink:

The file ‘JavaScript.tmLanguage’ defines what every word or character in a .js file is, or is part of. That is, whether it is a constant, operator, parameter or it is within a comment or function definition. This information is then used by your current theme to decide what colour and format it should use.

I can see that ‘x’ is considered to be ‘source.js support.constant.js’, whereas ‘z’ is considered just part of ‘source.js’. This accounts for the different colours, although it’s difficult to say whether this is intentional (by the author of the tmLanguage file).

Andy.

0 Likes