introduction to coffeescript
Post on 12-May-2015
95 Views
Preview:
DESCRIPTION
TRANSCRIPT
• What is Coffee Script ?• How it can help us ?• Coffee in Browse ?• Advantage?• Disadvantage?
Coffee Script
Basic Introduction
What is Coffee Script-1
• Coffee Script is a programming language that transcompiles to JavaScript that means source code of a coffee script as its input and outputs the source code into another programming language.
• The language adds syntactic sugar inspired by Ruby, Python and Haskell to enhance JavaScript's brevity and readability, adding sophisticated features like list comprehension and pattern matching.
• Coffee Script is an attempt to expose the good parts of JavaScript
What is Coffee Script-1
• The golden rule of Coffee Script is: "It's just JavaScript". The code compiles one-to-one into the equivalent JS, and there is no interpretation at runtime.
• You can use any existing JavaScript library seamlessly from Coffee Script (and vice-versa). a simple way. The compiled output is readable and pretty-printed, will work in every JavaScript runtime, and tends to run as fast or faster than the equivalent handwritten JavaScript.
What is Coffee Script -2
• Cooperate with already existing JS libraries (like jQuery, Facebook JS SDK, Google API etc.)
• Code compiles one-to-one into the equivalent JS
• Pass through JSLint without warnings
How it can help us ?• Less lines of code with better readability,
• Code easy to understand, and maintain
• Standard code encapsulation and variables
• Protection (no var anymore)
• But... even if you are writing code in CoffeeScript You should know how JavaScript`s concepts work
Example
Coffee Script in Your Browser1. <script src=“coffee-script.js” type=“text/javascript”></script>
2. <script type=“text/CoffeScript”>
3. firstname = prompt “what is your first name?”4. lastname= prompt “what is your last name ?”5. fullname=firstname+ lastname
6. Alert “Hello, #{fullname}”
7. </script>
Advantages
• All the good Feature of java script are present in coffee script
• English Like syntax and no return statement required.
• You don`t have to debug any “ }” in your script
• With the proper use of white space you can make your script more readable as well as maintainable
Advantages
• The ability to write code that works in old versions of Internet Explorer without having to compromise or shim
• Not having to worry about JavaScript pitfalls like trailing commas and automatic semicolon insertion
• Cleaned up semantics where every language construct can be used as part of a larger expression
Disadvantages
• When you are using coffee script , there`s an additional compilation step involved in the process.
• Coffee Script is very sensitive to whitespace, counting a tab as a single space.
• The compiler provides very rudimentary diagnostic information in the case of errors.
Disadvantages
• Priority rules are not always intuitive, sometimes causing sub-expressions to end up in unexpected places.
• Debugging is a major problem because the compiled code is not always readable.
• But Coffee script team is trying to solve this in the future
The Final Word
• Sole purpose is to remove the rough edges from the java script and provide a smooth way of programming in JavaScript
• Now Programming in JavaScript has an easy way and hard way –the choice is yours.
• To learn Coffee script syntax you can refer Coffeescript.org
top related