-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding one line to Backbone.js to provide seamless CoffeeScript integ…
…ration (inheritance from Backbone.Model, View, Collection) + tests
- Loading branch information
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Quick Backbone/CoffeeScript tests to make sure that inheritance | ||
# works correctly. | ||
|
||
{ok, equal, deepEqual} = require 'assert' | ||
{Model, Collection, Events} = require '../backbone' | ||
|
||
|
||
# Patch `ok` to store a count of passed tests... | ||
count = 0 | ||
oldOk = ok | ||
ok = -> | ||
oldOk arguments... | ||
count++ | ||
|
||
|
||
class Document extends Model | ||
|
||
fullName: -> | ||
@get('name') + ' ' + @get('surname') | ||
|
||
tempest = new Document | ||
id : '1-the-tempest', | ||
title : "The Tempest", | ||
name : "William" | ||
surname : "Shakespeare" | ||
length : 123 | ||
|
||
ok tempest.fullName() is "William Shakespeare" | ||
ok tempest.get('length') is 123 | ||
|
||
|
||
class ProperDocument extends Document | ||
|
||
fullName: -> | ||
"Mr. " + super | ||
|
||
properTempest = new ProperDocument tempest.attributes | ||
|
||
ok properTempest.fullName() is "Mr. William Shakespeare" | ||
ok properTempest.get('length') is 123 | ||
|
||
|
||
console.log "passed #{count} tests" |
1d57168
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just wondering if I could use Coffee classes to declare Backbone objects yesterday. Nice!
1d57168
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!