SHARE
TWEET

Untitled

a guest Jan 21st, 2020 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Person {
  2.     constructor(cpr, name, age) {
  3.         this.cpr = cpr
  4.         this.name = name
  5.         this.age = age
  6.     }
  7.  
  8.     toString(){return this.name +' - '+this.cpr + ' - ' + this.age}
  9.     valueOf(){return this.cpr}
  10.     equals(p){
  11.         if(p == this){
  12.             if(p.cpr === this.cpr){
  13.                 return true
  14.             }
  15.         } else {
  16.             return false
  17.         }
  18.     }
  19. }
  20.  
  21. Person.compare = function(p1,p2){
  22.     if(p1.name < p2.name){return -1}
  23.     if(p1.name > p2.name){return 1}
  24.     if(p1.name == p2.name){return 0}
  25. }
  26.  
  27. let p = new Person(1234, 'Benjamin', 22)
  28. let p1 = new Person(1234, 'Keivn', 4567890)
  29.  
  30. console.log(p.toString())
  31. console.log(p.valueOf())
  32. console.log(p.equals(p))
  33. console.log(Person.compare(p,p))
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top