Giter VIP home page Giter VIP logo

programming-in-coffeescript's Introduction

Programming in CoffeeScript

This repository contains all of the source code for the book, Programming in CoffeeScript. As I write the book this repository will be updated with any changes, additions, subtractions, etc... that come along.

The book can be purchaseed pretty much anywhere you can buy books, both in print and eBook formats (ePUB, MOBI, PDF).

Here's where you can find a comprehensive list of those places:

http://books.markbates.com

Dedication
Preface
Acknowledgements
About The Author
Part 1: Core CoffeeScript
  Chapter 1: Getting Started
    The CoffeeScript REPL
    In-Browser Compilation
    Command Line Compilation
    The CoffeeScript CLI
  Chapter 2: The Basics
    Syntax
    Scope and Variables
    String Interpolation, Heredocs, and Comments
    Extended Regular Expressions
  Chapter 3: Control Structures
    Operators and Aliases
    If/Unless
    Switch/Case Statements
  Chapter 4: Functions and Arguments
    Function Basics
    Arguments
    Default Arguments
    Splats...
  Chapter 5: Collections and Iterations
    Arrays
    Ranges
    Objects/Hashes
    Loops and Iteration
    Comprehensions
    The `do` Keyword
  Chapter 6: Classes
    Defining Classes
    Defining Functions
    The `constructor` function
    Scope in Classes
    Extending Classes
    Class-level Functions
    Prototype Functions
    Binding (-> vs. =>)
Part 2: CoffeeScript in Practice
  Chapter 7: Cake and Cakefiles
    Getting Started
    Creating Cake Tasks
    Running Cake Tasks
    Using Options
    Invoking Other Tasks
  Chapter 8: Testing with Jasmine
    Installing Jasmine
    Setting up Jasmine
    Introduction to Jasmine
    Unit Testing
    Before and After
    Custom Matchers
  Chapter 9: Intro to Node.js
    What is Node.js?
    Installing Node
    Getting Started
    Streaming Responses
    Building a CoffeeScript Server
    Trying Out the Server
  Chapter 10: Example: Todo List Part 1 (Server-side)
    Installing and Setting up Express
    Setting up MongoDB using Mongoose
    Writing the Todo API
    Querying with Mongoose
  Chapter 11: Example: Todo List Part 2 (Client-side w/ jQuery)
    Priming the HTML with Twitter Bootstrap
    Interacting with jQuery
    Hooking up the New Todo Form
    Cleaning up the Todo List with Underscore.js Templates
    Listing Existing Todos
    Updating Todos
    Deleting Todos
  Chapter 12: Example: Todo List Part 3 (Client-side w/ Backbone.js)
    What is Backbone.js?
    Setting up Backbone.js
    Writing our Todo Model and Collection
    Listing Todos using a View
    Creating New Todos
    A View Per Todo
    Updating and Validating Models from Views
    Deleting Models from Views

programming-in-coffeescript's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

programming-in-coffeescript's Issues

Non of the code runs in chapter 11 (Can't set headers after they are sent)

If you try running any code in chapter 11 you get the same error "Can't set headers after they are sent"

Express 3.0.0beta7
CoffeeScript version 1.3.3
Node v0.8.2

http.js:644
throw new Error('Can't set headers after they are sent.');
^
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (http.js:644:11)
at ServerResponse.res.setHeader (/Users/work/todo/node_modules/express/node_modules/connect/lib/patch.js:62:20)
at ServerResponse.res.header (/Users/work/todo/node_modules/express/lib/response.js:280:8)
at ServerResponse.res.json (/Users/work/todo/node_modules/express/lib/response.js:135:8)
at Create.global.Responder.Responder.complete (/Users/work/todo/src/controllers/responders/responder.js:27:25)
at Promise.__bind (/Users/work/todo/src/controllers/responders/responder.js:3:63)
at Promise.addBack (/Users/work/todo/node_modules/mongoose/lib/promise.js:120:8)
at Promise.EventEmitter.emit (events.js:88:17)
at Promise.emit (/Users/work/todo/node_modules/mongoose/lib/promise.js:59:38)
at Promise.complete (/Users/work/todo/node_modules/mongoose/lib/promise.js:70:20)

Chpt 10: Setting up MongoDB using Mongoose = image error

Hi

Not sure where you want bug reports about issues in the book? is it ok here? or should I sent to your publisher?

In Chapter 10: section: Setting up MongoDB using Mongoose:

Example 3: app.coffee - you say we need to update our app to include the todo model we just created...I assume you mean we need to update app.coffee with the require todos_controller -- but the image included in the Kindle version I have - does not show any controller line being added - it just repeats a previous code block that did not have any changes to it in this one.

Its missing this line:

require("#{__dirname}/src/controllers/todos_controller")

and the rest of the section expects that you did that - but if you follow explicitly you missed it and won't get the results the book shows! :)

hope this helps someone!

cheers.

chpt 10

Hi

Im starting to run into some trouble with Chapter 10 not working out. I think this is the same as your other issue which is the express framework has updated and your code is a tad out of sync. Are you planning on providing any code updates for the changes in Express to latest?

( great book so far! )

cheers

Tj

coffeescript and javascript handle return values in constructors differently

I was once under the false impression that it didn't matter what value a constructor returned with used with new as in p = new Person()

But, I've told by the gurus at the node.js and coffee-script github sites that this is not so.

In general, with coffeescript it's best to use class as in: class Person ...

But, if one tries to create a function that acts as a constructor in CoffeeScript, there is at least one gotcha. The follow three short scripts demonstrate the problem, which apparently the writers of CoffeeScript and JavaScript will simply have to deal with. (The gurus who create/maintain these languages don't think its their problem and closed my bug report immediately.)

So, Mark, as someone who writes books on CoffeeScript, I hope the following might help you warn your readers. (BTW: like your book)


#--------------------------   person.coffee -----------------------------------

Person = (name) ->
    @name = name
    @greet_friend = (friend) ->
        console.log("Hello #{friend}. My name is #{@name}.")
    ###
    wierd CoffeeScript/Node.js error:
    You will get and error if you comment the next line out
    and explicitly return the greet_friend method above.
    ###
    return null



Person.prototype.hello_world =  ->
    console.log("#{@name} says hello world.")


p = new Person('Fred')
p.greet_friend('Mary')
p.hello_world()

#-------------------------   bad_person.coffee ---------------------
Person = (name) ->
    @name = name
    @greet_friend = (friend) ->
        console.log("Hello #{friend}. My name is #{@name}.")
    ###
    wierd CoffeeScript v1.6.1/Node.js v0.8.22 error:
    This will bomb because we've commented out
    the 'return null' line below, which means
    that CoffeeScript will explicitly return
    the greet_friend method above.

    return null
    ###

Person.prototype.hello_world =  ->
    console.log("#{@name} says hello world.")


p = new Person('Fred')
p.greet_friend('Mary')
p.hello_world()

#------------------- redeemed_bad_person.js -----------------------

// Generated by CoffeeScript 1.6.1 
// but modified by me. I removed the
// explicit return of the greet_friend
// method.

(function() {
  var Person, p;

  Person = function(name) {
    this.name = name;
    this.greet_friend = function(friend) {
      return console.log("Hello " + friend + ". My name is " + this.name + ".");
    };
    /*
        wierd CoffeeScript v1.6.1/Node.js v0.8.22 error:
        This version works because we do not
      explicitly return the greet_friend 
      method above.
    */

  };

  Person.prototype.hello_world = function() {
    return console.log("" + this.name + " says hello world.");
  };

  p = new Person('Fred');

  p.greet_friend('Mary');

  p.hello_world();

}).call(this);




Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.