classPerson{name:string;age:number;constructor(name:string, age:number) {this.name= name;this.age= age; }dosomething() :void{console.log(this.name+'在干点啥'); } }classStudentextendsPerson{phone:number;constructor(name:string, age:number, phone:number) {super(name, age);// super 调用父...
private name: string; private phone: string; constructor(name: string, phone: string) { this.name = name; this.phone = phone; } public info() { console.log(`我是 ${this.name} 手机号 ${this.formatPhone()}`) } private formatPhone() { return this.phone.replace(/(\d{3})\d{4}(...
本文首发于itsuki.cn个人博客泛型首先, 我们来写一个函数: loggerNum 函数, 这个函数的作用是 console.log 输入数字值, 然后将该值返回: {代码...} 假如说我...
可以使用静态方法classDateUtil {staticformatDate() { }//格式化日期staticdiffDateByDay() { }//两个日期之间的天数计算staticdiffDateByHour() { }//两个日期之前的小时计算statictimeConversion(restTime: number) { }//天 时分秒}//静态方法DateUtil.formatDate()export { }...
formatDate(date: Date, format?: string): string - 格式化日期 formatDate(new Date(), 'YYYY-MM-DD HH:mm:ss'); // '2023-04-01 12:30:45' isLeapYear(year: number): boolean - 判断是否为闰年 isLeapYear(2024); // true getDaysInMonth(year: number, month: number): number - 获取月份天数...
import { defineComponent } from 'vue' import type { PropType } from 'vue' interface InfoFormat { code: { type: number, required: true } msg:{ type: string } } export default defineComponent({ props:{ info: { type: Object as PropType<InfoFormat>, } }, }) 注意...
tslint.formatOnSave设为true则编辑器会对格式在保存的时候进行整理。 (3)TypeScript相关插件 TSLint(deprecated)是一个通过tslint.json配置在你写TypeScript代码时,对你的代码风格进行检查和提示的插件。关于TSLint的配置,我们会在后面讲解如何配置,它的错误提示效果在我们之前的例子已经展示过了。 TSLint Vue加强了对...
classPerson{privatename:string;privatephone:string;constructor(name:string,phone:string){this.name=name;this.phone=phone;}publicinfo(){console.log(`我是${this.name}手机号${this.formatPhone()}`)}privateformatPhone(){returnthis.phone.replace(/(\d{3})\d{4}(\d{3})/,'$1***$2');}}con...
classPerson{privatename:string;privatephone:string;constructor(name:string,phone:string){this.name=name;this.phone=phone;}publicinfo(){console.log(`我是${this.name}手机号${this.formatPhone()}`)}privateformatPhone(){returnthis.phone.replace(/(\d{3})\d{4}(\d{3})/,'$1***$2');}}con...
console.log(DateUtils.formatDate:,DateUtils.formatDate(newDate())); 5.接口 5.1抽象类和抽象方法 //一、抽象类和抽象方法 //在class前加上abstract关键字,该类就变成了抽象类。 //抽象类作为其他派生类的基类使用,就是为被别的类继承的。 //简单讲就是无法进行实例化的类。