Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Shapes = (function() {
- Object.prototype.extends = function (properties) {
- function f() {};
- var prop;
- f.prototype = Object.create(this);
- for (prop in properties) {
- f.prototype[prop] = properties[prop];
- };
- f.prototype._super = this;
- return new f();
- }
- var shape = {
- init: function init(x1, y1, color) {
- this.x1 = x1;
- this.y1 = y1;
- this.color = color;
- return this;
- },
- toString: function toString() {
- var output = "A[" + this.x1 + ", " + this.y1 + "], " + "color = " + this.color;
- return output;
- }
- };
- var circle = shape.extends({
- init: function init(x1, y1, r, color) {
- this._super.init(x1, y1, color);
- this.radius = r;
- return this;
- },
- toString: function toString() {
- var output = "O[" + this.x1 + ", " + this.y1 + "], radius = " + this.radius + ", color = " + this.color;
- return output;
- }
- });
- var rectangle = shape.extends({
- init: function init(x1, y1, width, height, color) {
- this._super.init(x1, y1, color);
- this.width = width;
- this.height = height;
- return this;
- },
- toString: function toString() {
- var output = "A[" + this.x1 + ", " + this.y1 + "], width = " +
- this.width + ", height = " + this.height + ", color = " + this.color;
- return output;
- }
- });
- var triangle = shape.extends({
- init: function init(x1, y1, x2, y2, x3, y3, color) {
- this._super.init(x1, y1, color);
- this.x2 = x2;
- this.y2 = y2;
- this.x3 = x3;
- this.y3 = y3;
- return this;
- },
- toString: function toString() {
- var output = "A[" + this.x1 + ", " + this.y1 + "], " +
- "B[" + this.x2 + ", " + this.y2 + "], " +
- "C[" + this.x3 + ", " + this.y3 + "], " +
- "color = " + this.color;
- return output;
- }
- });
- var line = shape.extends({
- init: function init(x1, y1, x2, y2, color) {
- this._super.init(x1, y1, color);
- this.x2 = x2;
- this.y2 = y2;
- return this;
- },
- toString: function toString() {
- var output ="A[" + this.x1 + ", " + this.y1 + "], " +
- "B[" + this.x2 + ", " + this.y2 + "], " +
- "color = " + this.color;
- return output;
- }
- });
- var segment = line.extends({
- init: function init(x1, y1, x2, y2, color) {
- this._super.init(x1, y1, x2, y2, color);
- return this;
- },
- toString: function toString() {
- return this._super.toString();
- }
- });
- return {
- shape: shape,
- circle: circle,
- rectangle: rectangle,
- triangle: triangle,
- line: line,
- segment: segment
- }
- }());
- var l = Object.create(Shapes.line).init(2, 2, 6, 6, "EFEFEF");
- console.log(l.toString());
- console.log();
- var se = Object.create(Shapes.segment).init(7, 7, 12, 12, "123456");
- console.log(se.toString());
- console.log();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement