JavaScript
Article
By Craig Buckler

Will JavaScript Function Without the ‘function’ Statement?

By Craig Buckler

Are you fed up typing ‘function’ in JavaScript code every few minutes? Should it be shortened? JavaScript inventor Brendan Eich thinks so and he revealed the following options during his keynote speech at Web Directions @media in London last month.

The first alternative is the florin symbol:


ƒ myfunction() { … }

I quite like it. It stands out nicely in code and it looks like the f in function. Unfortunately, you won’t find it in all coding fonts and it’s tricky to type (in Windows, hold down Alt and type 0131 on your numeric keypad. Mac users should try the Special Characters palette).

--ADVERTISEMENT--

Next, we have the lambda symbol:


λ myfunction() { … }

The JavaScript geeks will think that’s very cool! Unfortunately, it suffers the same problems as the florin and you can’t even type it in Windows.

Finally, Brendan offered the plain old hash:


# myfunction() { … }

The majority of the audience voted for this symbol. It’s certainly easier to type, although I’m not sure it’ll stand out significantly in JavaScript code.

Other options may be raised and you should note that ‘function’ can still be used if you prefer it … your existing code won’t break.

As well as reducing your typing effort, the bandwidth savings could be colossal. For example, the minified jQuery library would become 4.3% smaller. That may only be 3Kb, but multiply that against the millions of downloads it receives every day.

Do you like any of these function-replacing options? Please cast your vote on the SitePoint poll or leave your comments below…

More:
Recommended
Sponsors
The most important and interesting stories in tech. Straight to your inbox, daily. Get Versioning.
Login or Create Account to Comment
Login Create Account