[TxMt] Better JavaScript functions

Andreas Wahlin andreaswahlin at bredband.net
Mon Sep 19 15:13:59 UTC 2005


> You can use alternation: (foo|bar). So combined it'd be:
>
>     match = "^\\s*(?:this\\.|(var\\b)?\\s*)([a-zA-Z_]\\w*)\\s*=\\s* 
> (function)\\s*\\(([^)]*)\\)";
>
> I used the (?:foo|bar) form to avoid making it a capture. It is btw  
> possible to prefix the expression with (?x) to enter “extended’  
> mode where whitespace and comments are ignored, so we can pretty  
> print it:
>
>     match = "(?x)
>         ^\\s*                # begin-of-line + leading space
>         (?: this\\.          # literal this.
>           | (var\\s+)        # -> or literal var (capture #1)
>           |                  # -> or nothing
>         )
>         ([a-zA-Z_]\\w*)\\s*  # actual function name (capture #2)
>         =\\s*                # literal =
>         (function)\\s*       # function keyword (capture #3)
>         \\(([^)]*)\\)        # the parameters (capture #4)
>     ";
>
> Don't know if you find that more readable or not…

"That'll work to" - Jet Li's The One :)

<That page shows 'private' functions, 'privileged' functions, and  
public functions. If the examples don't answer your question, feel  
free to contact me off-list (as I fear we're straying far from  
TextMate topics. ;)>

Thanks a lot Gavin, great page!
I got the idea from Crockford from the beginning, but this seems a  
bit more comprehensive.

Andreas


More information about the textmate mailing list