const people = function(name = String, age = Number) {
this.name = name
this.age = age
this.sayName = function() {
console.log(`My name is ${this.name}`)
// 記得要return this
return this
}
this.sayAge = function() {
console.log(`My age is ${this.age}`)
// 記得要return this
return this
}
}
const man = new people('lin', 27)
console.log(man)
man.sayName().sayAge()
people { name: 'lin', age: 27, sayName: [Function], sayAge: [Function] }
My name is lin
My age is 27