cevilio

Add methods Array and Object Prototype

Jul 8th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <body>
  4.  
  5. <h2>JavaScript Objects</h2>
  6.  
  7. <p id="demo"></p>
  8.  
  9. <script>
  10.  
  11. function Person(first, last, age, eye) {
  12.     this.firstName = first;
  13.     this.lastName = last;
  14.     this.age = age;
  15.     this.eyeColor = eye;
  16. }
  17. Person.prototype.name = function() {
  18.     return this.firstName + " " + this.lastName
  19. };
  20.  
  21. Array.prototype.getsize = function() {return this.length};
  22.  
  23. var myFather = new Person("John", "Doe", 50, "blue");
  24. document.getElementById("demo").innerHTML = [1,33,2,23].getsize();
  25. </script>
  26.  
  27. </body>
  28. </html>
Advertisement
Add Comment
Please, Sign In to add comment