Slide 25
Slide 25 text
"use strict";
// class
class Person {
constructor(name, age) {
this.name = name
this.age = age
}
getInfo() {
let name = this.name;
let age = this.age;
let nextAge = this.age + 1;
// enhanced object literal
return {
name,
age,
nextAge
};
}
}
// @@toStringTag ͚ͳ͍ͱ [object object]
Person.prototype[Symbol.toStringTag] =
"Person";
var alice = new Person('alice', 13);
var bob = new Person('bob', 15);
console.log('' + alice);
console.log(bob.getInfo());
͜Μͳ෩ʹॻ͚Δ