Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use lambda expressions in JQuery?

In jQuery lambda functions, the user asks about debugging lambda expressions in JQuery. I've searched many sites, and I'm unable to find examples of lambda expressions in JQuery. Does anyone know if this is possible, and if so where can I find some examples?

like image 656
Dave Avatar asked Feb 11 '11 00:02

Dave


1 Answers

Lambda expression are used (among other things) as a shorthand to specifying anonymous functions (also called anonymous delegates or anonymous methods). That is, pointers to function that you define on-the-fly.

See this common JQuery Ajax example:

$.ajax({
  url: "test.html",
  context: document.body,
  success: function(){
    $(this).addClass("done");
  } });

The success parameter uses Javascript's on-the-fly function definition and pointer. So yes, there is a kindof lambda syntax for anonymous function in javascript. In fact, this is very similar to VB.NET's lambda syntax, used very powerfully for both expression trees and anonymous functions:

Dim newNinjaList = NinjaList.Where(Function(n) n.primaryWeapon = "dagger")

So, you could say there's a lambda syntax in JQuery, though many would consider it inelegant.

If you mean lambda expressions to specify expression trees, then the answer is simple: no, JQuery does not use any kind of lambda syntax for expression trees.

like image 148
Patrick Karcher Avatar answered Oct 03 '22 04:10

Patrick Karcher