class Rectangle {
constructor(height, width) {
this.name = 'Rectangle'
this.height = height
this.width = width
}
sayName() {
console.log(
// here this references to the caller
`Hi I am a ${this.name} with height ${this.height}, width ${this.width}.`
)
}
get area() {
return this.height * this.width
}
set area(value) {
this.height = this.width = Math.sqrt(value)
}
}
// extends is possible
class Square extends Rectangle {
constructor(length) {
super(length, length)
this.name = 'Square'
}
sayName() {
super.sayName()
console.log(`Square talks too much`)
}
}
['pikachu', 'carapuce', 'miaouss'].forEach(p => console.log(p)) // data iteration
['pikachu', 'carapuce', 'miaouss'].filter(p => p.length < 8) // data filtering
['pikachu', 'carapuce', 'miaouss'].map(p => `pokemon ${p}`) // data transformation
['pikachu', 'carapuce', 'miaouss']
.filter(p => p.length < 8)
.map(p => `pokemon ${p}`)
.forEach(p => console.log(p)) // composability