Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add some examples

  • Loading branch information...
commit 5e00e125c5dfc89298b1b301d135faea13791576 1 parent 056bd90
Jay Adkisson authored
16  examples/ninja.js
... ...
@@ -0,0 +1,16 @@
  1
+var Person = C(function(person) {
  2
+  person.init = function(isDancing) { this.dancing = isDancing };
  3
+  person.dance = function() { return this.dancing };
  4
+});
  5
+
  6
+var Ninja = C(Person, function(ninja, person) {
  7
+  ninja.init = function() { person.init.call(this, false) };
  8
+  ninja.swingSword = function() { return 'swinging sword!' };
  9
+});
  10
+
  11
+var p = Person(true);
  12
+p.dance(); // => true
  13
+
  14
+var n = Ninja();
  15
+n.dance(); // => false
  16
+n.swingSword(); // => 'swinging sword!'
24  examples/shapes.js
... ...
@@ -0,0 +1,24 @@
  1
+// from http://onestepback.org/articles/poly/
  2
+
  3
+var Shape = C(function(shape) {
  4
+  shape.moveTo = 
  5
+  shape.init = function(x, y) { this.x = x; this.y = y; };
  6
+  shape.move = function(x, y) { this.moveTo(this.x + x, this.y + y); };
  7
+});
  8
+
  9
+var Rectangle = C(Shape, function(rect, shape) {
  10
+  // @override
  11
+  rect.init = function(x, y, width, height) {
  12
+    shape.init.call(this, x, y);
  13
+    this.w = w;
  14
+    this.h = h;
  15
+  };
  16
+});
  17
+
  18
+var Circle = C(Shape, function(circle, shape) {
  19
+  // @override
  20
+  circle.init = function(x, y, radius) {
  21
+    shape.init.call(this, x, y);
  22
+    this.radius = radius;
  23
+  };
  24
+});

0 notes on commit 5e00e12

Please sign in to comment.
Something went wrong with that request. Please try again.