In that called function, we will then split up the options argument into separate variables to used later.
Javascript
Here's how it's frequently done in Javascript:
var options;
options = {
id: 1,
name: "bob",
address: "123 main street",
city: "new york",
state: "ny",
zip: 10027
};
({
myFunction: function(options) {
var address, city, id, name, state, title, zip;
id = options.id
name = options.name
title = options.title
address = options.address
city = options.city
state = options.state
zip = options.zip;
return console.log('name', name);
}
});
CoffeeScript
Here's how it can be done in CoffeeScript:
options =
id: 1
name: "bob"
address: "123 main street"
city: "new york"
state: "ny"
zip: 10027
myFunction: (options) ->
{ id, name, title, address, city, state, zip } = options # << Destructing Assignment
console.log 'name', name
The CoffeeScript implementation, using Destructing Assignment is a nice improvement.
Javascript 1.7
Granted Javascript 1.7 provides Destructing Assignment, but if you rely on that, then you'll need to worry about end user browser compatibility and the higher likely hood of developers falling into the trap of using proprietary extra non-cross-browser features, e.g., Mozilla's for each.Conclusion
This is one small example of why you should be using CoffeeScript instead of raw Javascript.Here are a few more reasons to use CoffeeScript:
- Fewer lines to write and maintain
- More expressive (easier to understand) code
- String interpolation
- Consistent, readable, pretty-printed generated Javascript
- Generally runs faster than typical Javascript hard-coded "equivalent" code
References
http://jashkenas.github.io/coffee-script/http://js2coffee.org/
great article. its helpful for me. we also provide web services in lahore visit us Web development services in Lahore
ReplyDeleteIts a great pleasure reading your post.Its full of information I am looking for and I love to post a comment that "The content of your post is awesome" Great work.
ReplyDeleteseo services
Thank you for the update, very nice site..
ReplyDeleteseo company
ReplyDeleteThank you for taking the time to publish this information very useful!
digital marketing agency
This blog is so nice to me. I will keep on coming here again and again. Visit my link as well..
ReplyDeletecheap web hosting in lahore
Thanks for sharing this amazing post. I am a Writer at Assignments Planet that provides online assignment writing service for students in the UK. It has professional writers that will make you the best assignment on any topic you provide.
ReplyDeleteIt is truly a well-researched content and excellent wording. I got so engaged in this material that I couldn’t wait reading. I am impressed with your work and skill. Thanks.
ReplyDeleteBest SEO Services in Lahore
Wow, excellent post. I'd like to draft like this too - taking time and real hard work to make a great article. This post has encouraged me to write some posts that I am going to write soon.
ReplyDeleteBest SEO Services
good website. latest technology news
ReplyDeleteWeb Development Company in Lahore is the leading provider of web development products and services in Pakistan. From complete web design to custom application development, our team can create any digital solution you can imagine.
ReplyDeleteWe offer a wide range of services like web development, website design, ecommerce stores and blogs. We develop sites for both PC and mobile devices.
ReplyDeleteThe company is to become the best website designing company in Lahore, by providing reliable Affordable Website Designing Services, with a work culture that is positive, creative and dynamic.
ReplyDeleteWeb Designing Company
Social Media Marketing
Most web site design company executives can talk fluent English and feature pretty appropriate communication skills.
ReplyDeleteWe offer a range of services that include SEO, web designing, mobile application development and internet marketing.
ReplyDeleteA web development company is a business that specializes in developing websites.
ReplyDeleteBy getting Pixaltech to work for your business, you get the best talent to craft and work upon your Social Media Marketing strategy.
ReplyDeleteSocial Media Marketing for Business Success
Graphic Design Company Graphic Design Services
A nice website development is a must-have for every business that wants to succeed.
ReplyDeleteWeb development Lahore and innovative team work closely to upgrade the era used on your internet site.
ReplyDeleteIndia's best Mobile App Development Company
ReplyDeleteEcommerce is a great way to promote customised products. Visit if you're looking for the best eCommerce App development company in the US.
ReplyDeleteWe are top Mobile App Development Company
ReplyDeleteReally enjoyed your post! I loved the way you explored the topic from different angles and offered practical advice. Do you have any recommendations for further reading or resources on this? Can’t wait to dive deeper!
ReplyDelete