Created
October 29, 2013 15:11
-
-
Save DimitarChristoff/7216505 to your computer and use it in GitHub Desktop.
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
require(['prime/prime'], function(prime){ | |
var Rectangle = prime({ | |
constructor: function(width, height){ | |
return this.setwidth(width).setHeight(height); | |
}, | |
setWidth: function(width){ | |
this.width = width; | |
return this; // allow chaining | |
}, | |
setHeight: function(height){ | |
this.height = height; | |
return this; | |
}, | |
squareRoot: function(){ | |
return this.height * this.width; | |
} | |
}); | |
var Square = prime({ | |
// subclass of Rectangle | |
extend: Rectangle, | |
constructor: function(side){ | |
return this.setSide(side); | |
}, | |
setSide: function(side){ | |
// both sides are the same | |
this.width = this.height = side; | |
return this; | |
}, | |
setWidth: function(width){ | |
return this.setSide(width); | |
}, | |
setHeight: function(height){ | |
return this.setSide(height); | |
} | |
}); | |
var square = new Square(30); | |
square.setWidth(5); // local | |
console.log(square.height); // 5 | |
console.log(square.squareRoot()); // from parent proto of Rectangle, 25 | |
console.log(square instanceof Rectangle); // true | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment