Skip to content

Commit

Permalink
add prototyping demo b00tc4mp#163
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelbarzi committed Sep 30, 2024
1 parent 8878b0c commit 57e1f8b
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions stuff/js/prototyping/person.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
var Person = function (name, surname, age, city) {
this.name = name
this.surname = surname
this.age = age
this.city = city
}

Person.prototype.talk = function () {
return this.name + ': πŸ—£οΈ'
}

Person.prototype.eat = function () {
return this.name + ': πŸ”'
}

Person.prototype.pee = function () {
return this.name + ': πŸ’¦'
}

Person.prototype.poo = function () {
return this.name + ': πŸ’©'
}

//var aaron = { name: 'Aaron', surname: 'Barrios', age: 26, city: 'Cornella' }
//var anna = { name: 'Anna', surname: 'Gonzalez', age: 27, city: 'Hospitalet' }
//var cisco = { name: 'Francisco', surname: 'Sanchez', age: 39, city: 'Barcelona' }
// ...

var aaron = new Person('Aaron', 'Barrios', 26, 'Cornella')
var anna = new Person('Anna', 'Gonzalez', 27, 'Hospitalet')
var cisco = new Person('Francisco', 'Sanchez', 39, 'Barcelona')

cisco.run20kmh = function () { return this.name + ': πŸƒβ€β™‚οΈπŸ’¨ 20km/h ...' }
cisco.poo = function () { return this.name + ': NOOP' }


var students = [aaron, anna, cisco, /* ... */]

console.log(aaron.talk())
console.log(anna.talk())
console.log(cisco.talk())
console.log(cisco.run20kmh())
console.log(anna.eat())
console.log(aaron.pee())
console.log(cisco.poo())


// VM953: 39 Aaron: πŸ—£οΈ
// VM953: 40 Anna: πŸ—£οΈ
// VM953: 41 Francisco: πŸ—£οΈ
// VM953: 42 Francisco: πŸƒβ€β™‚οΈπŸ’¨ 20km / h ...
// VM953: 43 Anna: πŸ”
// VM953: 44 Aaron: πŸ’¦
// VM953: 45 Francisco: NOOP
// undefined

0 comments on commit 57e1f8b

Please sign in to comment.