Skip to content

Instantly share code, notes, and snippets.

@dyoder
Created July 29, 2009 21:50
Show Gist options
  • Save dyoder/158420 to your computer and use it in GitHub Desktop.
Save dyoder/158420 to your computer and use it in GitHub Desktop.
new function(_) { // create the closure
// create the package object
var shapes = new base2.Package(this, {
name: "shapes",
version: "1.0",
exports: "PI,Circle,Rectangle"
});
// evaluate the imported namespace
eval(this.imports);
var PI = 3.14;
var Shape = Base.extend({
consructor: function(x, y) {
this.move(x, y);
},
x: 0,
y: 0,
getArea: Undefined,
move: function(x, y) {
this.x = Number(x);
this.y = Number(y);
}
});
var Circle = Shape.extend({
consructor: function(x, y, radius) {
this.base(x, y);
this.radius = Number(radius);
},
radius: 0,
getArea: function() {
return PI * Math.pow(this.radius, 2);
}
});
var Rectangle = Shape.extend({
consructor: function(x, y, width, height) {
this.base(x, y);
this.width = Number(width);
this.height = Number(height);
},
width: 0,
height: 0,
getArea: function() {
return this.width * this.height;
}
});
// evaluate the exported namespace (this initialises the Package)
eval(this.exports);
}
eval(base2.shapes.namespace);
var circle = new Circle( 5, 5, 10 );
console.log( circle.getArea() );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment