Advertisement
avr39ripe

jsPointProtoAdv

Mar 15th, 2021
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <title>Study</title>
  6. </head>
  7. <body>
  8.     <script>
  9.         'use strict'
  10.         function Point(pX, pY) {
  11.             // let this = {};
  12.             this.x = pX;
  13.             this.y = pY;
  14.             this.color='red'
  15.             //[[Prototype]]
  16.            
  17.             // return this;
  18.         }
  19.  
  20.         Point.prototype.print = function () { console.log(`(${this.x},${this.y})`); }
  21.         Point.prototype.getX = function () { return this.x; };
  22.         Point.prototype.getY = function () { return this.y; };
  23.         Point.prototype.setX = function (pX) {
  24.             if (pX >= 0) {
  25.                 this.x = pX;
  26.                 return true;
  27.             };
  28.             return false;
  29.         }
  30.         Point.prototype.setY = function (pY) {
  31.             if (pY >= 0) {
  32.                 this.y = pY;
  33.                 return true;
  34.             };
  35.             return false;
  36.         }
  37.         //Point.prototype.color = 'red';
  38.         Point.prototype.getColor = function () { return this.color; };
  39.         Point.prototype.setColor = function (pColor) { this.color = pColor; };
  40.  
  41.         {
  42.  
  43.             let p1 = new Point(21, 22);
  44.             let p2 = new Point(211, 212);
  45.             Point.prototype.move = function (dX, dY) { this.x += dX; this.y += dY; };
  46.             Point.prototype = {};
  47.             let p3 = new Point(26, 7);
  48.  
  49.             p1.print();
  50.             p1.setX(42);
  51.             p1.move(10, 20);
  52.             p1.print();
  53.             p2.move(4, 4);
  54.             p2.print();
  55.             p2.setY(33);
  56.  
  57.             p1.print();
  58.             p2.print();
  59.  
  60.             p3.print();
  61.             p3.move(3, 3);
  62.             p3.print();
  63.  
  64.             console.log(p1);
  65.             console.log(p2);
  66.            
  67.         }
  68.     </script>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement