I doubt this is possible, and I’m certain to do it in a production environment would be an impressively bad idea. This is just one of those hypothetical “I-wonder-if-I-could…” things.
I was wondering if it is possible to modify or extend how the browser JavaScript engine parses the code at run-time. For example: if I tried to use C# style lambda syntax in JavaScript:
var x = myJsObjCollection.Where(a=>a.ID == 2);
Could I modify the parsing of the script and intercept the lambda code and parse it myself?
I doubt it.
The engine which parses and executes the javascript is on the client’s browser, and as such cannot be modified or changed by any website (I would hope).
Potentially you could use javascript supported types and syntax to describe a lambda expression and then have your own javascript library which expands it to valid javascript calls.
However, it would not be that useful since javascript functions are already super flexible. Your code above in valid JS would look like the equivalent c# delegate:
Which isn’t a whole lot more work to type.
Update
To take Bob’s Idea a couple steps further, you could potentially write something like this:
Then your Where function would look something like:
And you could call it:
Working example at http://jsbin.com/ifufu/2/edit.