Skip to content

Instantly share code, notes, and snippets.

@juandopazo
Created March 30, 2011 13:01
Show Gist options
  • Save juandopazo/894335 to your computer and use it in GitHub Desktop.
Save juandopazo/894335 to your computer and use it in GitHub Desktop.
Class definition example
class Point {
<closed, prototype: Object.prototype>,
class method fromString(s) {
return new Point(parse(s));
},
private method repaint() {
console.log('moved!');
},
new (x, y) {
this.x = x;
this.y = y;
},
method move(x, y) {
this.x = x;
this.y = y;
this.repaint();
}
}
class Point3D {
<frozen: class, sealed: prototype, superclass: Point>,
get z(val) {
if (val === undefined) {
val = 0;
}
return val;
},
new (x, y, z) {
super(x, y);
this.z = z;
}
}
// This can also be used to create complex objects
var o = {
<prototype: Array.prototype, frozen>,
get x(val) {
return 2;
},
set x(val) {
throw new Error("read only property");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment