当前位置: 动力学知识库 > 问答 > 编程问答 >

sublimetext2 - Adding syntax highlighting to Sublime Text for JavaScript

问题描述:

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???

网友答案:

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.

网友答案:

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:

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.

分享给朋友:
您可能感兴趣的文章:
随机阅读: