Javascript code highlight

In Javascript, about 99.9% of the time I define functions like:

var app = {}

app.test=function() {
        // code

The javascirpt highlighting only highlights the word “function”. Is it possible for “app.test=function()” to be highlighted?

You can actually paste whatever example code you want to play with, right into the “Sample text” pane, then click on the text you want to affect, and change its colors like so:

Looks like both “app” and “func” (or in your case test) would be identifiers, so changing them would change other identifiers as you see above.

The thing is “app.test=function” is a pattern, not a literal. Would the method outlined above work with the endless types of functions which are created in this pattern?

app.sync=function() {}
app.toHtml=function() {} {}

I recently tested a handful of javascript editors and editors which are specifically geared towards javascript understand the syntax and highlight the line appropriately.

There are so many ways of defining a function in JS, it’s difficult to cover them all properly. That said I’d be interested in being able to offer highlighting support in this specific context but UDL is not my area of expertise. @ericp can you weigh in on the potential complexity involved in supporting this?

I can only think of 2 ways to define a function.

  1. window scoped: function xyz() {}

  2. named function expressions:

    abc=function() {} {}

There are functions which are executed immediately as:

(function xyz( str ) { alert(str)  }('hello') )

which would have the same highlighting as #1.

So really just 2 situations need to be considered.

Don’t forget; = function() {} = function() {}
var foo = { bar: function() {} }

I might still be forgetting some. Those might all be essentially the same to you and I but not to a lexer.

Still looks like 2 cases:

Case 1: the word function is preceded by an equal sign

Case 2: it is not

As I said, the way you and I interpret this logic is not the same as a lexer does. Anyway again - I am not the expert on this, we’ll have to wait for @ericp to weigh in.