我有以下课程:
export class PlatformIcon {
constructor() {
this.platform = '';
this.userAgent = '';
}
get icon() {
console.log('logging');
switch (this.platform.name) {
case 'www':
return 'fa fa-desktop';
break;
case 'mobi':
return 'fa fa-mobile';
break;
case 'ios':
return 'fa fa-apple';
break;
case 'blackberry':
return 'icon-blackberry';
break;
case 'android':
return 'fa fa-android';
break;
default:
return '';
}
}
}
实例化时,getter似乎进入无限循环,即console.log()
语句反复记录。