tags:

views:

148

answers:

3

is there any way to map the λ key to the function keyword? so that these work:

var rFalse = λ() {
  return false;
}

(λ(){
  var str = "i'm in a closure";
}());

window.onload = λ() {
  alert('window loaded');
}

I know that they are attempting to put a shortened function keyword in ecmascript v6, but I'm wondering if it is possible to do it now.

+8  A: 

JavaScript does not offer aliasing of keywords, so it is not possible make the syntax you're trying to use valid.

Matt
thanks I have been trying to find a way, but i guess I'll just have to hope that they confirm it in ECMA 6
Rixius
+2  A: 

I wouldn't think so, since function is a keyword... You'll have hard time passing your program through the parser.

Kobi
Unless of course, you write your own implementation.
ChaosPandion
Well, if you do that, that's almost trivial.
Kobi
yeah the only benefit of that is for your own personal use as a custom server-side javascript interpretor
Rixius
@Rixius, @Kobi - Incidentally, I have been working on my own for the past month. Mainly as a fun learning experience. I have mostly everything working, I just need to read through all those dry algorithms for the built in objects and implement them. :(
ChaosPandion
I would love to modify my own implementation of V8 and use it for myself on a server-side, but I don't know c++ and don't have enough free time to learn it for a simple pet project.
Rixius
+2  A: 

It is possible, just not natively. You'd have to look into implementing or using an existing DSL.

A good example could be CoffeeScript, which includes an Extras script for running on client-side via:

<script type="text/coffeescript">

Their contents are converted to and reinserted into the document as JavaScript by:

<script src="extras/coffee-script.js"></script>

However, keep in mind that client-side DSLs risk drastically increasing load times and ruining the user experience -- CoffeeScript is primarily server-side for a reason.

Jonathan Lonowski
I am looking into this and see plenty of promise; may be using my own custom `type="application/λ-script"` soon enough;
Rixius