Advertisement
ForeverDev

Untitled

Oct 8th, 2014
220
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 newPerson(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 love "
  19.             var iter = 0
  20.             for (var 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. var grant = new newPerson( //args: name, weight, age, interests
  37.     "Grant",
  38.     1000,
  39.     69,
  40.     {1 : "men", 2 : "dicksucking", 3 : "8 year old boys"}
  41. )
  42.  
  43. grant.shout(grant.tag)
  44. //output: My name is Grant.
  45. grant.shout(grant.weight)
  46. //output: I weigh 1000 pounds.
  47. grant.shout(grant.interests)
  48. //output: I love men, dicksucking, and 8 year old boys!
  49. grant.shout("I like penis!")
  50. //output: Grant shouted: I like penis!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement