Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coffeescript/ch6 : "package" is a reserved keyword. #49

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions coffeescript/06_applications.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h2>Stitch it up</h2>
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" ]

Expand All @@ -102,7 +102,7 @@ <h2>Stitch it up</h2>
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}"
Expand Down
4 changes: 2 additions & 2 deletions coffeescript/07_the_bad_parts.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h2>Global variables</h2>
})();
</code></pre>

<p>Notice how CoffeeScript initializes variables (using <code>var</code>) 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 <code>package</code> variable in a Class function:</p>
<p>Notice how CoffeeScript initializes variables (using <code>var</code>) 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 <code>package</code> variable in a Class function:</p>

<p><span class="csscript"></span></p>

Expand Down Expand Up @@ -491,7 +491,7 @@ <h3>Strict mode usage</h3>
class window.Spine
</code></pre>

<p>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.</p>
<p>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.</p>

<h2>JavaScript Lint</h2>

Expand Down
4 changes: 2 additions & 2 deletions coffeescript/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -41,4 +41,4 @@ task :generate do
end
end

task :default => :generate
task :default => :generate
10 changes: 5 additions & 5 deletions coffeescript/all.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ <h2>Initial setup</h2>

<p>One of the easiest ways to initially play around with the library is to use it right inside the browser. Navigate to <a href="http://coffeescript.org">http://coffeescript.org</a> and click on the <em>Try CoffeeScript</em> 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.</p>

<p>You can also convert JavaScript back to CoffeeScript using the <a href="http://js2coffee.org/">js2coffee</a> project, especially useful when migration JavaScript projects to CoffeeScript.</p>
<p>You can also convert JavaScript back to CoffeeScript using the <a href="http://js2coffee.org/">js2coffee</a> project, especially useful when migrating JavaScript projects to CoffeeScript.</p>

<p>In fact, you can use the browser-based CoffeeScript compiler yourself, by including <a href="http://jashkenas.github.com/coffee-script/extras/coffee-script.js">this script</a> in a page, marking up any CoffeeScript script tags with the correct <code>type</code>.</p>

Expand Down Expand Up @@ -1252,7 +1252,7 @@ <h2>Stitch it up</h2>
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" ]

Expand All @@ -1267,7 +1267,7 @@ <h2>Stitch it up</h2>
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}"
Expand Down Expand Up @@ -1546,7 +1546,7 @@ <h2>Global variables</h2>
})();
</code></pre>

<p>Notice how CoffeeScript initializes variables (using <code>var</code>) 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 <code>package</code> variable in a Class function:</p>
<p>Notice how CoffeeScript initializes variables (using <code>var</code>) 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 <code>package</code> variable in a Class function:</p>

<p><span class="csscript"></span></p>

Expand Down Expand Up @@ -1952,7 +1952,7 @@ <h3>Strict mode usage</h3>
class window.Spine
</code></pre>

<p>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.</p>
<p>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.</p>

<h2>JavaScript Lint</h2>

Expand Down
4 changes: 2 additions & 2 deletions coffeescript/chapters/01_introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.
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.
6 changes: 3 additions & 3 deletions coffeescript/chapters/06_applications.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]

Expand All @@ -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}"
Expand Down Expand Up @@ -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).
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).
6 changes: 0 additions & 6 deletions coffeescript/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@
<h1><a href="index.html">The Little Book on CoffeeScript</a></h1>
</header>

<div id="notice">
<p>An <a href="http://shop.oreilly.com/product/0636920024309.do">updated version of the book</a> is now available in Paperback, PDF and Kindle versions from O'Reilly.</p>

<a href="http://shop.oreilly.com/product/0636920024309.do"><img src="site/covers.gif"></a>
</div>

<div id="content">
<ol class="pages">
<li><a href="01_introduction.html">Introduction</a></li>
Expand Down