I'm interested in not writing the word function so many time in my code. I'm not intending to write for the browser, I am planning on writing server-side javascript (embedded V8).
I could write a pre-processor that processes my scripts and converts the shorthand into standard javascript but it seems like a silly step. Is there a way to modify the parser to make "f" or "ƒ" or "*" an alias of "function"? I haven't used C in about 10 years so its pretty ruff tracing the code down... So far I have made a heap: V(f_symbol, "f") and a token: K(F, "f", 0) However, I haven't been having good luck modifying parser.cc and I have no idea if I am headed in the right direction or how much road is ahead of me. Any pointers would be greatly appreciated... In my opinion the word 'function' is just fodder anyway. A function could be implied by the use of curly braces. A function and an object literal could be differentiated based upon the syntax. I would hope that the next version of the JavaScript standard makes the use of the word function optional. Furthermore the change should only be needed in the parsing of the script so there shouldn't be any runtime performance impact. On Dec 15, 6:03 pm, Stephan Beal <[email protected]> wrote: > On Tue, Dec 15, 2009 at 11:16 PM, Joshaven <[email protected]> wrote: > > For example is this (or a variant) a possibility for javascript > > syntax: > > var myFunction = *{return 'Hello World';}; > > > Can some character like "*" be expanded to "function ()" when the > > javascript source is being interpreted? > > > This shortcut would make code a lot prettier! > > > For extra credit I would also like to see the parentheses optional. > > The JavaScript standard specifies no preprocessor (as C and C++ do), so this > isn't possible in vanilla JS. And v8 implements only vanilla JS + a small > handful of features to make embedding easier (a.g. custom get/set > interceptors). > > You can actually use the $ character as a function or object name: > > var $ = function() {...} > > but $ is used by many web toolkits, and shouldn't be used (IMO) in client > code, to avoid collisions. > > -- > ----- stephan bealhttp://wanderinghorse.net/home/stephan/ -- v8-users mailing list [email protected] http://groups.google.com/group/v8-users
