Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Object.size = function(object) {
- var size = 0
- for (key in object) {
- if (object.hasOwnProperty(key)) {
- size++
- }
- }
- return size
- }
- function person(name, weight, age, interests) {
- this.tag = name
- this.weight = weight
- this.age = age
- this.interests = interests
- this.shout = function(say) {
- if (typeof say == "object") {
- var finish = "I like "
- var iter = 0
- for (phrase in say) {
- iter++
- finish = finish + ((iter > 1 && iter < Object.size(say)) && ", " || (iter == Object.size(say)) && ", and " || "") + say[phrase] + (iter == Object.size(say) && "!" || "")
- }
- console.log(finish)
- } else if (typeof say == "string" || typeof say == "number") {
- console.log(
- say == this.tag && "My name is " + this.tag + "." ||
- say == this.age && "I am " + this.age + " years old." ||
- say == this.weight && "I weigh " + this.weight + " pounds." ||
- this.tag + " shouted: " + say
- )
- }
- }
- }
- //args: name, weight, age, interests
- var Grant = new person (
- "Grant",
- 1000,
- 69,
- ["men", "dicksucking", "8 year old boys"]
- )
- var David = new person (
- "David",
- 145,
- 14,
- ["hot girls", "being badass", "shitting on " + Grant.tag]
- )
- Grant.shout(Grant.tag) //output: My name is Grant.
- Grant.shout(Grant.weight) //output: I weigh 1000 pounds.
- Grant.shout(Grant.interests) //output: I like men, dicksucking, and 8 year old boys!
- Grant.shout("I like penis!\n") //output: Grant shouted: I like penis!
- David.shout(David.tag) //output: My name is David.
- David.shout(David.weight) //output: I weigh 145 pounds.
- David.shout(David.interests) //output: I like hot girls, being badass, and shitting on Grant!
- 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