Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Study</title>
- </head>
- <body>
- <script>
- 'use strict'
- class Point {
- static className = "Class Point";
- static objects = 0;
- static printObjCount() { console.log(`Class Point was used for: ${Point.objects} objects`); }
- constructor(pX, pY) {
- //let this = {};
- console.log('Point constructor');
- this.x = pX;
- this.y = pY;
- ++Point.objects;
- }
- print() { console.log(`(${this.x},${this.y})`); }
- getX() { return this.x; }
- getY() { return this.y; }
- setX(pX) {
- if (pX >= 0) {
- this.x = pX;
- return true;
- };
- return false;
- }
- setY(pY) {
- if (pY >= 0) {
- this.y = pY;
- return true;
- };
- return false;
- }
- move(dX, dY) { this.x += dX; this.y += dY; }
- }
- class ColorPoint extends Point {
- constructor(pX, pY, pColor = 'red') {
- console.log('ColorPoint constructor');
- super(pX, pY);
- this.color = pColor;
- }
- getColor() { return this.color; }
- setColor(pColor) { this.color = pColor; }
- print() {
- super.print();
- console.log(`[${this.color}]`);
- }
- }
- /* function Point(pX, pY, pColor = 'red') {
- // let this = {};
- this.x = pX;
- this.y = pY;
- this.color = pColor;
- //[[Prototype]]
- // return this;
- }
- Point.prototype.print = function () { console.log(`(${this.x},${this.y})`); }
- Point.prototype.getX = function () { return this.x; };
- Point.prototype.getY = function () { return this.y; };
- Point.prototype.setX = function (pX) {
- if (pX >= 0) {
- this.x = pX;
- return true;
- };
- return false;
- }
- Point.prototype.setY = function (pY) {
- if (pY >= 0) {
- this.y = pY;
- return true;
- };
- return false;
- }
- //Point.prototype.color = 'red';
- Point.prototype.getColor = function () { return this.color; };
- Point.prototype.setColor = function (pColor) { this.color = pColor; };
- */
- {
- /* let p1 = new Point(21, 22);
- let p2 = new Point(211, 212);
- //Point.prototype.move = function (dX, dY) { this.x += dX; this.y += dY; };
- //Point.prototype = {};
- let p3 = new Point(26, 7);
- p1.print();
- p1.setX(42);
- p1.move(10, 20);
- p1.print();
- p2.move(4, 4);
- p2.print();
- p2.setY(33);
- p1.print();
- p2.print();
- p3.print();
- p3.move(3, 3);
- p3.print();
- console.log(p1);
- console.log(p2);
- */
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement