通用函式
在介面中:
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) {
}
}