{"ScriptPreparationCode":"// Point1: ES6 class\r\n\r\nclass Point {\r\n constructor(x, y) {\r\n this.x = x;\r\n this.y = y;\r\n }\r\n\r\n getX() {\r\n return this.x;\r\n }\r\n\r\n getY() {\r\n return this.y;\r\n }\r\n\r\n add(point) {\r\n return new Point(this.getX() \u002B point.x, this.y \u002B point.y);\r\n }\r\n\r\n sub(point) {\r\n return new Point(this.x - point.x, this.y - point.y);\r\n }\r\n}\r\nvar Point1 = Point;\r\n\r\n// Point1Private: ES6 class with private fields declared\r\n\r\nclass PointVPrivate {\r\n #x;\r\n #y;\r\n constructor(x, y) {\r\n this.#x = x;\r\n this.#y = y;\r\n }\r\n\r\n add(point) {\r\n return new PointVPrivate(this.#x \u002B point.#x, this.#y \u002B point.#y);\r\n }\r\n\r\n sub(point) {\r\n return new PointVPrivate(this.#x - point.#x, this.#y - point.#y);\r\n }\r\n}\r\n\r\nvar Point1Private = PointVPrivate;\r\n\r\n// Point2: Prototypal class\r\n\r\nfunction Point2(x, y) {\r\n this.x = x;\r\n this.y = y;\r\n}\r\nPoint2.prototype.add = function(point) {\r\n return new Point2(this.x \u002B point.x, this.y \u002B point.y);\r\n}\r\n\r\nPoint2.prototype.sub = function(point) {\r\n return new Point2(this.x - point.x, this.y - point.y);\r\n}\r\n\r\n// Point3: Object literal\r\n\r\nfunction Point3(x, y) {\r\n return {\r\n x,\r\n y,\r\n add: (point) =\u003E Point3(this.x \u002B point.x, this.y \u002B point.y),\r\n sub: (point) =\u003E Point3(this.x - point.x, this.y - point.y)\r\n }\r\n}\r\n\r\n// Point10: ES6 class with inheritance\r\n\r\nclass AbstractPoint10 {\r\n constructor(x, y) {\r\n this.x = x;\r\n this.y = y;\r\n }\r\n\r\n getX() {\r\n return this.x;\r\n }\r\n\r\n getY() {\r\n return this.y;\r\n }\r\n}\r\n\r\nclass Point10Class extends AbstractPoint10 {\r\n constructor(x, y) {\r\n super(x, y);\r\n }\r\n\r\n add(point) {\r\n return new Point10Class(this.getX() \u002B point.getX(), this.getY() \u002B point.getY());\r\n }\r\n\r\n sub(point) {\r\n return new Point10Class(this.getX() - point.getX(), this.getY() - point.getY());\r\n }\r\n}\r\n\r\nvar Point10 = Point10Class;\r\n\r\n// Point10Private: ES6 class with inheritance and private fields declared\r\n\r\nclass AbstractPoint10Private {\r\n #x;\r\n #y;\r\n constructor(x, y) {\r\n this.#x = x;\r\n this.#y = y;\r\n }\r\n\r\n getX() {\r\n return this.#x;\r\n }\r\n\r\n getY() {\r\n return this.#y;\r\n }\r\n}\r\n\r\nclass Point10PrivateClass extends AbstractPoint10Private {\r\n constructor(x, y) {\r\n super(x, y);\r\n }\r\n\r\n add(point) {\r\n return new Point10PrivateClass(this.getX() \u002B point.getX(), this.getY() \u002B point.getY());\r\n }\r\n\r\n sub(point) {\r\n return new Point10PrivateClass(this.getX() - point.getX(), this.getY() - point.getY());\r\n }\r\n}\r\n\r\nvar Point10Private = Point10PrivateClass;\r\n\r\n// Point20: Prototypal class with inheritance\r\n\r\nfunction AbstractPoint20(x, y) {\r\n this.x = x;\r\n this.y = y;\r\n}\r\n\r\nAbstractPoint20.prototype.getX = function() {\r\n return this.x;\r\n}\r\n\r\nAbstractPoint20.prototype.getY = function() {\r\n return this.y;\r\n}\r\n\r\nfunction Point20(x, y) {\r\n AbstractPoint20.call(this, x, y);\r\n}\r\n\r\nObject.setPrototypeOf(Point20.prototype, AbstractPoint20.prototype);\r\n\r\nPoint20.prototype.add = function(point) {\r\n return new Point20(this.getX() \u002B point.getY(), this.getX() \u002B point.getY());\r\n}\r\n\r\nPoint20.prototype.sub = function(point) {\r\n return new Point20(this.getX() - point.getY(), this.getX() - point.getY());\r\n}\r\n","TestCases":[{"Name":"ES6 Class","Code":"var p1 = new Point1(10, 10);\r\nvar p2 = new Point1(10, -10);\r\nvar sum = p1.add(p2);\r\nvar dif = p1.sub(p2);","IsDeferred":false},{"Name":"Function Prototype","Code":"var p1 = new Point2(10, 10);\r\nvar p2 = new Point2(10, -10);\r\nvar sum = p1.add(p2);\r\nvar dif = p1.sub(p2);","IsDeferred":false},{"Name":"Object Literal","Code":"var p1 = Point3(10, 10);\r\nvar p2 = Point3(10, -10);\r\nvar sum = p1.add(p2);\r\nvar dif = p1.sub(p2);","IsDeferred":false},{"Name":"ES6 Class with private properties","Code":"var p1 = new Point1Private(10, 10);\r\nvar p2 = new Point1Private(10, -10);\r\nvar sum = p1.add(p2);\r\nvar dif = p1.sub(p2);","IsDeferred":false},{"Name":"ES6 class with inheritance","Code":"var p1 = new Point10(10, 10);\r\nvar p2 = new Point10(10, -10);\r\nvar sum = p1.add(p2);\r\nvar dif = p1.sub(p2);","IsDeferred":false},{"Name":"ES6 class with inheritance and private fields declared","Code":"var p1 = new Point10Private(10, 10);\r\nvar p2 = new Point10Private(10, -10);\r\nvar sum = p1.add(p2);\r\nvar dif = p1.sub(p2);","IsDeferred":false},{"Name":"Function prototype with inheritance","Code":"var p1 = new Point20(10, 10);\r\nvar p2 = new Point20(10, -10);\r\nvar sum = p1.add(p2);\r\nvar dif = p1.sub(p2);","IsDeferred":false}]}