jquery的项目开发风格
<script>
class page {
constructor() {
this.init();
}
set name(value) {
this._name = value;
$('.name').text(value);
}
get name() {
return this._name;
}
async init() {
this.name = 'tom';
setTimeout(() => {
this.name = 'joe';
}, 1000);
await this.getData();
console.log('getData callback');
}
getData() {
return new Promise((resolve) => {
setTimeout(() => {
console.log('getData');
resolve('getData');
}, 2000);
})
}
}
$(() => {
new page();
});
</script>