981377660LMT / ts

ts学习
6 stars 1 forks source link

get 惰性求值 #399

Open 981377660LMT opened 1 year ago

981377660LMT commented 1 year ago
const person = {
    firstName: 'George',
    lastName: 'Costanza',
    fullName: `${person.firstName} ${person.lastName}`
};
错误 TS2448:在声明之前使用块范围变量“person”。

const person = {
    firstName: 'George',
    lastName: 'Costanza',
    get fullName() { return `${person.firstName} ${person.lastName}`; }
};

console.log(JSON.stringify(person));