Created
March 30, 2011 13:01
-
-
Save juandopazo/894335 to your computer and use it in GitHub Desktop.
Class definition example
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
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