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'
- function Point(pX, pY) {
- // let this = {};
- this.x = pX;
- this.y = pY;
- this.color='red'
- //[[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