标签:很多 target test pes tor val style erro get
const userInfo: any = undefined; class Test{ getName() { return userInfo.name; } getAge() { return userInfo.age; } } const test = new Test(); test.getName();
const userInfo: any = undefined; class Test{ getName() { try { return userInfo.name; } catch (e) { console.log(‘userinfo.name 不存在‘) } } getAge() { try { return userInfo.info; } catch (e) { console.log(‘userinfo.info 不存在‘) } } } const test = new Test(); test.getName();
const userInfo: any = undefined; function catchError(target: any, key: string, descriptor: PropertyDescriptor) { const fn = descriptor.value; descriptor.value = function () { try { fn(); } catch (e) { console.log(‘userinfo 存在问题‘) } } } class Test{ @catchError getName() { return userInfo.name; } @catchError getAge() { return userInfo.info; } } const test = new Test(); test.getAge();
标签:很多 target test pes tor val style erro get
原文地址:https://www.cnblogs.com/wzndkj/p/13488668.html