Using Coffeescript with KnockoutJS

A long time ago, I blogged about using KnockoutJS with ASP.NET MVC. While it was nice and all, this time around I decided to switch it up a bit with Coffeescript

CoffeeScript is nifty little language that compiles into Javascript. In my opinion, the advantages of using it (outside its inherent coolness) is that it is easier to pickup for someone coming from an OOP background as it adds some sort of a facade to Javascript’s truly functional nature, although you still have access to Javascript’s useful functional constructs. It also tends to be easier to read.

Let’s say I wanted to create a simple Login form tied to a view model, with the button triggering an Ajax. Here’s what my CoffeeScript and its generated Javascript equivalent would look like.

Now in my Html, all I just need to make a call to it.

Voila!

Advertisements
Using Coffeescript with KnockoutJS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s