implements 的用法
StringValidator.ts
1 export interface StringValidator { 2 isAcceptable(s: string): boolean; 3 3 }
LettersOnlyValidator.ts
1 import { StringValidator } from "./Validation"; 2 const lettersRegexp = /^[A-Za-z]+$/; 3 export class LettersOnlyValidator implements StringValidator { 4 isAcceptable(s: string) { 5 return lettersRegexp.test(s); 6 } 7 }
import:导入;
export :导出;
implementes StringValidator {}用法:
class LettersOnlyValidator implements StringValidator{
里面就必须要有 StringValidator设定的参数和方法
}