Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object.prototype.extends = function (parent) {
- // for old browsers version
- if (!Object.create) {
- Object.prototype.create = function (proto) {
- function F() { };
- F.prototype = proto;
- return new F;
- };
- };
- this.prototype = Object.create(parent.prototype);
- this.prototype.constructor = this;
- };
- // ----------Shape----------
- var Shape = (function () {
- var Shape = function (x, y, color) {
- this._x = x;
- this._y = y;
- this._color = color;
- };
- Shape.prototype = {
- toString: function () {
- var shapeInfo = "X:" + this._x + ", Y:" + this._y + ", Color in hexadecimal format:" + this._color;
- return shapeInfo;
- }
- };
- return Shape;
- }());
- // ----------Rectangle----------
- var Rectangle = (function () {
- var Rectangle = function (x, y, color, width, height) {
- Shape.call(this, x, y, color);
- this._width = width;
- this._height = height;
- };
- Rectangle.extends(Shape);
- Rectangle.prototype.toString = function () {
- return Shape.prototype.toString.call(this) +
- ", Width:" + this._width +
- ", Height:" + this._height;
- };
- return Rectangle;
- }());
- // ----------Triangle----------
- var Triangle = (function () {
- var Triangle = function (x, y, color, x2, y2, x3, y3) {
- Shape.call(this, x, y, color);
- this._x2 = x2;
- this._y2 = y2;
- this._x3 = x3;
- this._y3 = y3;
- };
- Triangle.extends(Shape);
- Triangle.prototype.toString = function () {
- return Shape.prototype.toString.call(this) +
- ", x2:" + this._x2 +
- ", y2:" + this._y2 +
- ", x3:" + this._x3 +
- ", y3:" + this._y3;
- };
- return Triangle;
- }());
- // ----------Segment----------
- var Segment = (function () {
- var Segment = function (x, y, color, x2, y2) {
- Shape.call(this, x, y, color);
- this._x2 = x2;
- this._y2 = y2;
- };
- Segment.extends(Shape);
- Segment.prototype.toString = function () {
- return Shape.prototype.toString.call(this) +
- ", x2:" + this._x2 +
- ", y2:" + this._y2;
- };
- return Segment;
- }());
- // ----------Point----------
- var Point = (function () {
- var Point = function (x, y, color) {
- Shape.call(this, x, y, color);
- };
- Point.extends(Shape);
- Point.prototype.toString = function () {
- return Shape.prototype.toString.call(this);
- };
- return Point;
- }());
- //var rectangle = new Rectangle(5, 4, "#FFF", 10, 12);
- //var triangle = new Triangle(6, 4, "#F54", 7, 17, 11, 25);
- //var segment = new Segment(2, 3, "#001", 5, 16);
- //var point = new Point(4, 5, "#ff9");
- //console.log(rectangle.toString());
- //console.log(triangle.toString());
- //console.log(segment.toString());
- //console.log(point.toString());
Advertisement
Add Comment
Please, Sign In to add comment