通用函数
在接口中:
interface IRunner {
runSafe<T extends IRunnable>(runnable: T): void;
}
在课堂上:
class Runner implements IRunner {
public runSafe<T extends IRunnable>(runnable: T): void {
try {
runnable.run();
} catch(e) {
}
}
}
功能简单:
function runSafe<T extends IRunnable>(runnable: T): void {
try {
runnable.run();
} catch(e) {
}
}