[Pkg-javascript-commits] [backbone] 30/74: Adding one line to Backbone.js to provide seamless CoffeeScript integration (inheritance from Backbone.Model, View, Collection) + tests

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:59:06 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.3.0
in repository backbone.

commit 1d57168c8f436f1f9b20a5fa7f13495610931b22
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Wed Oct 27 09:17:38 2010 -0400

    Adding one line to Backbone.js to provide seamless CoffeeScript integration (inheritance from Backbone.Model, View, Collection) + tests
---
 Rakefile          |  5 +++++
 backbone.js       |  1 +
 test/model.coffee | 43 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 49 insertions(+)

diff --git a/Rakefile b/Rakefile
index bf2672d..1ebeeb8 100644
--- a/Rakefile
+++ b/Rakefile
@@ -18,4 +18,9 @@ end
 desc "run JavaScriptLint on the source"
 task :lint do
   system "jsl -nofilelisting -nologo -conf docs/jsl.conf -process backbone.js"
+end
+
+desc "test the CoffeeScript integration"
+task :test do
+  system "coffee test/*.coffee"
 end
\ No newline at end of file
diff --git a/backbone.js b/backbone.js
index d3b28d3..6112759 100644
--- a/backbone.js
+++ b/backbone.js
@@ -695,6 +695,7 @@
     _.extend(child.prototype, protoProps);
     if (classProps) _.extend(child, classProps);
     child.prototype.constructor = child;
+    child.__super__ = parent.prototype;
     return child;
   };
 
diff --git a/test/model.coffee b/test/model.coffee
new file mode 100644
index 0000000..d456aea
--- /dev/null
+++ b/test/model.coffee
@@ -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"

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list