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>
- <div id="output"></div>
- <script>
- 'use strict'
- {
- function Point(pX, pY) {
- this.x = pX;
- this.y = pY;
- 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;
- }
- }
- let p1 = new Point(21, 22);
- /// p1.x = -123545;
- let p2 = new Point(211, 212);
- Point.prototype.move = function (dX, dY) { this.x += dX; this.y += dY; }
- let p3 = new Point(26, 7);
- p1.print();
- p1.setX(42);
- p2.print();
- p2.setY(33);
- p1.print();
- p2.print();
- p3.print();
- p2.move(5, 6);
- p2.print();
- p3.move(5, 6);
- p3.print();
- console.log(p1);
- console.log(p2);
- console.log(p3);
- console.log(p1.__proto__ == Point.prototype);
- console.log(p3.__proto__ == Point.prototype);
- console.log(p3.__proto__ == p1.__proto__);
- }
- </script>
- <h1></h1>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment