0

i have a single problem, in my sublime text 2 the syntax highlight of javascript takes this code

this.init = function(){};
this.init : function(){},

painting of "this" in lightblue and "init" in green...

but in this case...

this.init = null;
this.init : null,

is not happening... i want to highlight "this.*" in all cases of use...

like for example

this.init = function()
this.init : function()
this.init : true
this.init = true

how can i do that???

2 Answers 2

6

The default syntax highlighting for javascript in Sublime is not great.

I use JavascriptNext: https://github.com/Benvie/JavaScriptNext.tmLanguage

It improves on the default syntax hightlighting and also adds support for future ES6 syntax.

In your particular case it is more consistent on the coloring of the if values, though less consistent on the property values for the : syntax. But I think thats ok since its not actually valid syntax anyhow.

Comparison

Sign up to request clarification or add additional context in comments.

3 Comments

installing JavascriptNext by Package Control "this" are not in color... im using sublime text 2... –
Well it also depends on your syntax coloring. That variable will be consistently colored with jsnext, but it may be the same color as other things Try some different syntax highlighting, or if you want, design your own.
Wow! Thanks! Been anoyed by the weird difference in the behaviour for quite a while now.
0

Adding to ben336's answer, I tested your code with my Neon Color Scheme and a few different JavaScript language definitions, including JavaScriptNext, which actually did look the best:

this.init with Neon theme

The scopes for the init method are interesting (all are source.js, of course) -

this.init = function(); // meta.property.js variable.other.property.js
this.init : function(); // meta.function.js meta.function.json.js entity.name.function.js
this.init : true; // meta.function.js constant.other.object.key.js string.unquoted.label.js
this.init = true; // meta.function.js meta.property.js variable.other.property.js

Since the last 3 are function scoped they should be colored bright green, but the third one has a string scope and the last one a variable.other scope, so they pick up those colorings instead.

If you'd like, I can try to finagle the theme's function scope selectors to color the last 3 consistently - just open an issue or let me know here and I'll see what I can do.

2 Comments

installing JavascriptNext by Package Control "this" are not in color... im using sublime text 2...
are you using the Neon Color Scheme, and have you chosen JavaScriptNext from the syntax menu?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.