By Guillermo Cedillo
C# is becoming more like a functional language in every release; by the other side Javascript is a functional language that was treated as a misunderstood-object-oriented-script language ¬_¬. I hope in the next years these two languages become so closer that they share the same basic principles of the functional languages.
Right now I'm looking closer to two technologies that I think they are going to be something extraordinary: RX and LINQ.
LINQ is already a powerful extension to C#, but also there's an extension for Javascript. LINQ gives you a lot of freedom in data manipulation, together with jQuery gives you flexibility and lightness in reports of complex data, in custom controls, and in all that I thought were impossible in the client side.
Look at this example of LINQ in javascript:
// $.Enumerable
$.Enumerable.Range(1, 10).Where("$%2==0").ForEach("alert($)");
// TojQuery - Enumerable to jQuery
$.Enumerable.Range(1, 10)
.Select(function (i) { return $("<option>").text(i) })
.TojQuery()
.appendTo("#select1");
// toEnumerable - jQuery to Enumerable
var sum = $("#select1").children()
.toEnumerable()
.Select("parseInt($.text())")
.Sum(); // 55
It's the same thinking of LINQ in C#, and it's integrated with jQuery with endless possibilities!
The next technology is RX -as in Reactive Extension-. It's similar to LINQ and is also in C#, but it's focused to events. The beauty of RX is that suddenly something as complex as drag and drop in javascript is though and wrote as:
//Get the context with jQuery
var mouseDragMe = $("#mouseDragMe").context;
//Make it observable
var mouseMove = Rx.Observable.FromHtmlEvent(mouseDragMe, "mousemove");
var mouseUp = Rx.Observable.FromHtmlEvent(mouseDragMe, "mouseup");
var mouseDown = Rx.Observable.FromHtmlEvent(mouseDragMe, "mousedown");
//Describe the gesture
var mouseMoves = mouseMove
.Skip(1)
.Zip(mouseMove, function(left, right) {
return { x1 : left.clientX,
y1 : left.clientY,
x2 : right.clientX,
y2 : right.clientY };
});
var mouseDrags = mouseDown.SelectMany(function(md) {
return mouseMoves.TakeUntil(mouseUp);
});
mouseDrags.Subscribe(function(mouseEvents) {
$("#results").html(
"Old (X: " + mouseEvents.x1 + " Y: " + mouseEvents.y1 + ") " +
"New (X: " + mouseEvents.x2 + " Y: " + mouseEvents.y2 + ")");
});
If you followed the code you should notice that it is very clean and understandable, and it also integrates with jQuery... you know, endless possibilities ^_^
Javascript is something extraordinary, I'm looking forward to these and other technologies. With all the new concepts and new ideas that every day arise, I love more my profession as a humble Developer.