[TxMt] Better JavaScript functions

Andreas Wahlin andreaswahlin at bredband.net
Mon Sep 19 08:53:31 UTC 2005


>> FWIW, the second is not valid JS. The first is valid, as is:
>> var functionName = function( ... ){ ... }, but 'var' must not be  
>> followed by a dereferenced object.
>>
>

I then had to split it up into two

         {    name = "meta.function.js";
             match = "^\\s*this\\.([a-zA-Z_]\\w*)\\s*=\\s*(function)\ 
\s*\\(([^)]*)\\)";
             captures =
             {    1 = { name = "entity.name.function.js"; };
                 2 = { name = "storage.type.function.js"; };
                 3 = { name = "variable.parameter.function.js"; };
             };
         },
         {    name = "meta.function.js";
             match = "^\\s*(var\\b)?\\s*([a-zA-Z_]\\w*)\\s=\\s* 
(function)\\s*\\(([^)]*)\\)";
             captures =
             {    1 = { name = "storage.type.js"; };
                 2 = { name = "entity.name.function.js"; };
                 3 = { name = "storage.type.function.js"; };
                 4 = { name = "variable.parameter.function.js"; };
             };
         },

is there a better way?

Then I realized that you can also do it by prototype, thusly
object.prototype.functionName = function(arguments) { ... }
and made the following

         {    name = "meta.function.js";
             match = "^\\s*[a-zA-Z_]\\w*\\.(prototype)\\.([a-zA-Z_]\ 
\w*)\\s=\\s*(function)\\s*\\(([^)]*)\\)";
             captures =
             {    1 = { name = "support.constant.js"; };
                 2 = { name = "entity.name.function.js"; };
                 3 = { name = "storage.type.function.js"; };
                 4 = { name = "variable.parameter.function.js"; };
             };
         },

only problem here, is that the "object" isn't catched. For istance, I  
have
Array.prototype.get = function(get) { ... }
but Array does not get the support.class.js scope, how would one  
solve this?

Andreas



More information about the textmate mailing list