javascript - 求解let validators: {[s: string]: Vali.StringValidator;} = {};
PHP中文网
PHP中文网 2017-04-10 17:36:02
0
1
617

初学typescript

namespace Validation {
    export interface StringValidator {
        isAcceptable(s: string): boolean;
    }
    const numberRegexp = /^[0-9]+$/;
    export class ZipCodeValidator implements StringValidator {
        isAcceptable(s: string) {
            return s.length === 5 && numberRegexp.test(s);
        }
    }
}
//这句什么意思
let validators: { [s: string]: Validation.StringValidator; } = {};
//这里的中括号什么意思?
validators["ZIP code"] = new Validation.ZipCodeValidator();
PHP中文网
PHP中文网

认证高级PHP讲师

reply all(1)
黄舟
let validators: { [s: string]: Validation.StringValidator; } = {};

指定变量validators是一个对象,它里面的属性名是字符串类型的,属性值是Validation.StringValidator类型。中括号用来指定属性名的类型。

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template