Introduction to Coffeescript

15
By www.indiesjxe.com www.indiesinc.com

description

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. We are Java service provider company. Visit us http://www.indiesinc.com

Transcript of Introduction to Coffeescript

Page 1: Introduction to Coffeescript

By

www.indiesjxe.com www.indiesinc.com

Page 2: Introduction to Coffeescript

• What is Coffee Script ?• How it can help us ?• Coffee in Browse ?• Advantage?• Disadvantage?

Page 3: Introduction to Coffeescript

Coffee Script

Basic Introduction

Page 4: Introduction to Coffeescript

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

Page 5: Introduction to Coffeescript

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.

Page 6: Introduction to Coffeescript

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

Page 7: Introduction to Coffeescript

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

Page 8: Introduction to Coffeescript

Example

Page 9: Introduction to Coffeescript

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>

Page 10: Introduction to Coffeescript

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

Page 11: Introduction to Coffeescript

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

Page 12: Introduction to Coffeescript

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.

Page 13: Introduction to Coffeescript

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

Page 14: Introduction to Coffeescript

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

Page 15: Introduction to Coffeescript

Thank You !!!!

www.indiesinc.com