ForeverDev

Untitled

Oct 8th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Object.size = function(object) {
  2.     var size = 0
  3.     for (key in object) {
  4.         if (object.hasOwnProperty(key)) {
  5.             size++
  6.         }
  7.     }
  8.     return size
  9. }
  10.  
  11. function person(name, weight, age, interests) {
  12.     this.tag = name
  13.     this.weight = weight
  14.     this.age = age
  15.     this.interests = interests
  16.     this.shout = function(say) {
  17.         if (typeof say == "object") {
  18.             var finish = "I like "
  19.             var iter = 0
  20.             for (phrase in say) {
  21.                 iter++
  22.                 finish = finish + ((iter > 1 && iter < Object.size(say)) && ", " || (iter == Object.size(say)) && ", and " || "") + say[phrase] + (iter == Object.size(say) && "!" || "")
  23.             }
  24.             console.log(finish)
  25.         } else if (typeof say == "string" || typeof say == "number") {
  26.             console.log(
  27.                 say == this.tag && "My name is " + this.tag + "." ||
  28.                 say == this.age && "I am " + this.age + " years old." ||
  29.                 say == this.weight && "I weigh " + this.weight + " pounds." ||
  30.                 this.tag + " shouted: " + say
  31.             )
  32.         }
  33.     }
  34. }
  35.  
  36. //args: name, weight, age, interests
  37. var Grant = new person (
  38.     "Grant",
  39.     1000,
  40.     69,
  41.     ["men", "dicksucking", "8 year old boys"]
  42. )
  43.  
  44. var David = new person (
  45.     "David",
  46.     145,
  47.     14,
  48.     ["hot girls", "being badass", "shitting on " + Grant.tag]
  49. )
  50.  
  51. Grant.shout(Grant.tag)                      //output: My name is Grant.
  52. Grant.shout(Grant.weight)                   //output: I weigh 1000 pounds.
  53. Grant.shout(Grant.interests)                    //output: I like men, dicksucking, and 8 year old boys!
  54. Grant.shout("I like penis!\n")                  //output: Grant shouted: I like penis!
  55.  
  56. David.shout(David.tag)                      //output: My name is David.
  57. David.shout(David.weight)                   //output: I weigh 145 pounds.
  58. David.shout(David.interests)                    //output: I like hot girls, being badass, and shitting on Grant!
  59. David.shout("I'm so much cooler than " + Grant.tag + "!\n")     //output: I'm so much cooler than Grant!
Advertisement
Add Comment
Please, Sign In to add comment