Advertisement
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 newPerson(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 love "
- var iter = 0
- for (var 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
- )
- }
- }
- }
- var grant = new newPerson( //args: name, weight, age, interests
- "Grant",
- 1000,
- 69,
- {1 : "men", 2 : "dicksucking", 3 : "8 year old boys"}
- )
- grant.shout(grant.tag)
- //output: My name is Grant.
- grant.shout(grant.weight)
- //output: I weigh 1000 pounds.
- grant.shout(grant.interests)
- //output: I love men, dicksucking, and 8 year old boys!
- grant.shout("I like penis!")
- //output: Grant shouted: I like penis!
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement