diff --git a/coffeescript/06_applications.html b/coffeescript/06_applications.html index 5e25c85..8ada110 100644 --- a/coffeescript/06_applications.html +++ b/coffeescript/06_applications.html @@ -87,7 +87,7 @@

Stitch it up

express = require("express") argv = process.argv.slice(2) -package = stitch.createPackage( +pckg = stitch.createPackage( # Specify the paths you want Stitch to automatically bundle up paths: [ __dirname + "/app" ] @@ -102,7 +102,7 @@

Stitch it up

app.set "views", __dirname + "/views" app.use app.router app.use express.static(__dirname + "/public") - app.get "/application.js", package.createServer() + app.get "/application.js", pckg.createServer() port = argv[0] or process.env.PORT or 9294 console.log "Starting server on port: #{port}" diff --git a/coffeescript/07_the_bad_parts.html b/coffeescript/07_the_bad_parts.html index 15f9328..5c53088 100644 --- a/coffeescript/07_the_bad_parts.html +++ b/coffeescript/07_the_bad_parts.html @@ -85,7 +85,7 @@

Global variables

})(); -

Notice how CoffeeScript initializes variables (using var) automatically in the context their first used. Whilst it's impossible to shadow outer variables, you can still refer to and access them. You need to watch out for this, be careful that you're not reusing the name of an external variable accidentally if you're writing a deeply nested function or class. For example, here we're accidentally overwriting the package variable in a Class function:

+

Notice how CoffeeScript initializes variables (using var) automatically in the context they're first used. Whilst it's impossible to shadow outer variables, you can still refer to and access them. You need to watch out for this, be careful that you're not reusing the name of an external variable accidentally if you're writing a deeply nested function or class. For example, here we're accidentally overwriting the package variable in a Class function:

@@ -491,7 +491,7 @@

Strict mode usage

class window.Spine -

Whilst I recommend enabling strict mode, but it's worth noting that script mode doesn't enable any new features that aren't ready possible in JavaScript, and will actually slow down your code a bit by having the VM do more checks at runtime. You may want to develop with strict mode, and deploy to production without it.

+

Whilst I recommend enabling strict mode, but it's worth noting that strict mode doesn't enable any new features that aren't ready possible in JavaScript, and will actually slow down your code a bit by having the VM do more checks at runtime. You may want to develop with strict mode, and deploy to production without it.

JavaScript Lint

diff --git a/coffeescript/Rakefile b/coffeescript/Rakefile index 91defce..0906245 100644 --- a/coffeescript/Rakefile +++ b/coffeescript/Rakefile @@ -6,7 +6,7 @@ require "fileutils" def generate(page, template = "site/page.ms") Mustache.render( File.read(template), - page.merge(:content => RDiscount.new(File.read(page[:src])).to_html), + page.merge(:content => RDiscount.new(File.read(page[:src])).to_html) ) end @@ -41,4 +41,4 @@ task :generate do end end -task :default => :generate \ No newline at end of file +task :default => :generate diff --git a/coffeescript/all.html b/coffeescript/all.html index bbf3dad..3bc5ac8 100644 --- a/coffeescript/all.html +++ b/coffeescript/all.html @@ -47,7 +47,7 @@

Initial setup

One of the easiest ways to initially play around with the library is to use it right inside the browser. Navigate to http://coffeescript.org and click on the Try CoffeeScript tab. The site uses a browser version of the CoffeeScript compiler, converting any CoffeeScript typed inside the left panel to JavaScript in the right panel.

-

You can also convert JavaScript back to CoffeeScript using the js2coffee project, especially useful when migration JavaScript projects to CoffeeScript.

+

You can also convert JavaScript back to CoffeeScript using the js2coffee project, especially useful when migrating JavaScript projects to CoffeeScript.

In fact, you can use the browser-based CoffeeScript compiler yourself, by including this script in a page, marking up any CoffeeScript script tags with the correct type.

@@ -1252,7 +1252,7 @@

Stitch it up

express = require("express") argv = process.argv.slice(2) -package = stitch.createPackage( +pckg = stitch.createPackage( # Specify the paths you want Stitch to automatically bundle up paths: [ __dirname + "/app" ] @@ -1267,7 +1267,7 @@

Stitch it up

app.set "views", __dirname + "/views" app.use app.router app.use express.static(__dirname + "/public") - app.get "/application.js", package.createServer() + app.get "/application.js", pckg.createServer() port = argv[0] or process.env.PORT or 9294 console.log "Starting server on port: #{port}" @@ -1546,7 +1546,7 @@

Global variables

})(); -

Notice how CoffeeScript initializes variables (using var) automatically in the context their first used. Whilst it's impossible to shadow outer variables, you can still refer to and access them. You need to watch out for this, be careful that you're not reusing the name of an external variable accidentally if you're writing a deeply nested function or class. For example, here we're accidentally overwriting the package variable in a Class function:

+

Notice how CoffeeScript initializes variables (using var) automatically in the context they're first used. Whilst it's impossible to shadow outer variables, you can still refer to and access them. You need to watch out for this, be careful that you're not reusing the name of an external variable accidentally if you're writing a deeply nested function or class. For example, here we're accidentally overwriting the package variable in a Class function:

@@ -1952,7 +1952,7 @@

Strict mode usage

class window.Spine -

Whilst I recommend enabling strict mode, but it's worth noting that script mode doesn't enable any new features that aren't ready possible in JavaScript, and will actually slow down your code a bit by having the VM do more checks at runtime. You may want to develop with strict mode, and deploy to production without it.

+

Whilst I recommend enabling strict mode, but it's worth noting that strict mode doesn't enable any new features that aren't ready possible in JavaScript, and will actually slow down your code a bit by having the VM do more checks at runtime. You may want to develop with strict mode, and deploy to production without it.

JavaScript Lint

diff --git a/coffeescript/chapters/01_introduction.md b/coffeescript/chapters/01_introduction.md index 1bb39c2..4bcda5e 100644 --- a/coffeescript/chapters/01_introduction.md +++ b/coffeescript/chapters/01_introduction.md @@ -8,7 +8,7 @@ This book is completely open source, and was written by [Alex MacCaw](http://ale If you have any errata or suggestions, please don't hesitate to open a ticket on the book's [GitHub page](https://github.com/arcturo/library). Readers may also be interested in [JavaScript Web Applications by O'Reilly](http://oreilly.com/catalog/9781449307530/), a book I authored that explores rich JavaScript applications and moving state to the client side. -So let's dive right into it; why is CoffeeScript better than writing pure JavaScript? Well for a start, there's less code to write - CoffeeScript is very succinct, and takes white-space into account. In my experience this reduces code by a third to a half of the original pure JavaScript. In addition, CoffeeScript has some neat features, such as array comprehensions, prototype aliases and classes that further reduce the amount of typing you need to do. +So let's dive right into it; why is CoffeeScript better than writing pure JavaScript? Well for a start, there's less code to write - CoffeeScript is very succinct, and takes whitespace into account. In my experience this reduces code by a third to a half of the original pure JavaScript. In addition, CoffeeScript has some neat features, such as array comprehensions, prototype aliases and classes that further reduce the amount of typing you need to do. More importantly though, JavaScript has a lot of [skeletons in its closet](http://bonsaiden.github.com/JavaScript-Garden/) which can often trip up inexperienced developers. CoffeeScript neatly sidesteps these by only exposing a curated selection of JavaScript features, fixing many of the language's oddities. @@ -47,4 +47,4 @@ If `--output` is not specified, CoffeeScript will write to a JavaScript file wit As you can see above, the default extension of CoffeeScript files is `.coffee`. Amongst other things, this will allow text editors like [TextMate](http://macromates.com/) to work out which language the file contains, giving it the appropriate syntax highlighting. By default, TextMate doesn't include support for CoffeeScript, but you can easily install the [bundle to do so](https://github.com/jashkenas/coffee-script-tmbundle). -If all this compilation seems like a bit of an inconvenience and bother, that's because it is. We'll be getting onto ways to solve this by automatically compiling CoffeeScript files, but first lets take a look at the language's syntax. \ No newline at end of file +If all this compilation seems like a bit of an inconvenience and bother, that's because it is. We'll be getting onto ways to solve this by automatically compiling CoffeeScript files, but first lets take a look at the language's syntax. diff --git a/coffeescript/chapters/06_applications.md b/coffeescript/chapters/06_applications.md index e4d3387..ef71309 100644 --- a/coffeescript/chapters/06_applications.md +++ b/coffeescript/chapters/06_applications.md @@ -60,7 +60,7 @@ Now to actually boot up the Stitch server. Let's create a file called `index.cof express = require("express") argv = process.argv.slice(2) - package = stitch.createPackage( + pckg = stitch.createPackage( # Specify the paths you want Stitch to automatically bundle up paths: [ __dirname + "/app" ] @@ -75,7 +75,7 @@ Now to actually boot up the Stitch server. Let's create a file called `index.cof app.set "views", __dirname + "/views" app.use app.router app.use express.static(__dirname + "/public") - app.get "/application.js", package.createServer() + app.get "/application.js", pckg.createServer() port = argv[0] or process.env.PORT or 9294 console.log "Starting server on port: #{port}" @@ -244,4 +244,4 @@ For example, when it comes to templating, you can use [Mustache](http://mustache As for serving up application, [Hem](http://github.com/maccman/hem) is a great choice, supporting both CommonJS and NPM modules and integrating seamlessly with the CoffeeScript MVC framework [Spine](http://spinejs.com). [node-browsify](https://github.com/substack/node-browserify) is another similar project. Or if you want to go lower level with [express](http://expressjs.com/) integration, there's Trevor Burnham's [connect-assets](https://github.com/TrevorBurnham/connect-assets) -You can find a full list of CoffeeScript web framework plugins, on the [project's wiki](https://github.com/jashkenas/coffee-script/wiki/Web-framework-plugins). \ No newline at end of file +You can find a full list of CoffeeScript web framework plugins, on the [project's wiki](https://github.com/jashkenas/coffee-script/wiki/Web-framework-plugins). diff --git a/coffeescript/index.html b/coffeescript/index.html index 5ded00b..d42b7a1 100644 --- a/coffeescript/index.html +++ b/coffeescript/index.html @@ -14,12 +14,6 @@

The Little Book on CoffeeScript

-
-

An updated version of the book is now available in Paperback, PDF and Kindle versions from O'Reilly.

- - -
-
  1. Introduction