Home Download Buy Blog Forum Support

Unusual code decorating (JS)

Unusual code decorating (JS)

Postby granz on Sat Feb 25, 2012 3:21 pm

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?
granz
 
Posts: 2
Joined: Sat Feb 25, 2012 3:08 pm

Re: Unusual code decorating (JS)

Postby agibsonsw on Sat Feb 25, 2012 4:39 pm

x and y were previously (useless) properties, like layerX and layerY :o. 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 8-)
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm

Re: Unusual code decorating (JS)

Postby granz on Sat Feb 25, 2012 7:47 pm

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.
granz
 
Posts: 2
Joined: Sat Feb 25, 2012 3:08 pm

Re: Unusual code decorating (JS)

Postby agibsonsw on Sat Feb 25, 2012 8:14 pm

I think you're crediting ST with too much intelligence ;)

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.
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
agibsonsw
 
Posts: 901
Joined: Fri Jan 27, 2012 9:11 pm


Return to Technical Support

Who is online

Users browsing this forum: estmatic, Exabot [Bot], Google [Bot] and 23 guests