Permalink
Browse files

add some examples

  • Loading branch information...
1 parent 056bd90 commit 5e00e125c5dfc89298b1b301d135faea13791576 @jneen jneen committed Jan 3, 2012
Showing with 40 additions and 0 deletions.
  1. +16 −0 examples/ninja.js
  2. +24 −0 examples/shapes.js
View
16 examples/ninja.js
@@ -0,0 +1,16 @@
+var Person = C(function(person) {
+ person.init = function(isDancing) { this.dancing = isDancing };
+ person.dance = function() { return this.dancing };
+});
+
+var Ninja = C(Person, function(ninja, person) {
+ ninja.init = function() { person.init.call(this, false) };
+ ninja.swingSword = function() { return 'swinging sword!' };
+});
+
+var p = Person(true);
+p.dance(); // => true
+
+var n = Ninja();
+n.dance(); // => false
+n.swingSword(); // => 'swinging sword!'
View
24 examples/shapes.js
@@ -0,0 +1,24 @@
+// from http://onestepback.org/articles/poly/
+
+var Shape = C(function(shape) {
+ shape.moveTo =
+ shape.init = function(x, y) { this.x = x; this.y = y; };
+ shape.move = function(x, y) { this.moveTo(this.x + x, this.y + y); };
+});
+
+var Rectangle = C(Shape, function(rect, shape) {
+ // @override
+ rect.init = function(x, y, width, height) {
+ shape.init.call(this, x, y);
+ this.w = w;
+ this.h = h;
+ };
+});
+
+var Circle = C(Shape, function(circle, shape) {
+ // @override
+ circle.init = function(x, y, radius) {
+ shape.init.call(this, x, y);
+ this.radius = radius;
+ };
+});

0 comments on commit 5e00e12

Please sign in to comment.