TS学习笔记(内置对象、class类)
ECMAScript的内置对象
let bool:Boolean = new Boolean(1)
let n:Number = new Number(true)
let s:String = new String('123')
let date:Date = new Date()
let regexp:RegExp = /^1/
let e:Error = new Error('错误信息')
DOM和BOM内置对象
let body: HTMLElement = document.body;
let allDiv: NodeList = document.querySelectorAll('div');
let div:HTMLElement = document.querySelector('div') as HTMLDivElement
document.addEventListener('click', function (e: MouseEvent) {
});
interface HTMLElementTagNameMap {
"a": HTMLAnchorElement;
"abbr": HTMLElement;
"address": HTMLElement;
"applet": HTMLAppletElement;
"area": HTMLAreaElement;
"article": HTMLElement;
"aside": HTMLElement;
"audio": HTMLAudioElement;
"b": HTMLElement;
"base": HTMLBaseElement;
"bdi": HTMLElement;
"bdo": HTMLElement;
"blockquote": HTMLQuoteElement;
"body": HTMLBodyElement;
"br": HTMLBRElement;
"button": HTMLButtonElement;
"canvas": HTMLCanvasElement;
"caption": HTMLTableCaptionElement;
"cite": HTMLElement;
"code": HTMLElement;
"col": HTMLTableColElement;
"colgroup": HTMLTableColElement;
"data": HTMLDataElement;
"datalist": HTMLDataListElement;
"dd": HTMLElement;
"del": HTMLModElement;
"details": HTMLDetailsElement;
"dfn": HTMLElement;
"dialog": HTMLDialogElement;
"dir": HTMLDirectoryElement;
"div": HTMLDivElement;
"dl": HTMLDListElement;
"dt": HTMLElement;
"em": HTMLElement;
"embed": HTMLEmbedElement;
"fieldset": HTMLFieldSetElement;
"figcaption": HTMLElement;
"figure": HTMLElement;
"font": HTMLFontElement;
"footer": HTMLElement;
"form": HTMLFormElement;
"frame": HTMLFrameElement;
"frameset": HTMLFrameSetElement;
"h1": HTMLHeadingElement;
"h2": HTMLHeadingElement;
"h3": HTMLHeadingElement;
"h4": HTMLHeadingElement;
"h5": HTMLHeadingElement;
"h6": HTMLHeadingElement;
"head": HTMLHeadElement;
"header": HTMLElement;
"hgroup": HTMLElement;
"hr": HTMLHRElement;
"html": HTMLHtmlElement;
"i": HTMLElement;
"iframe": HTMLIFrameElement;
"img": HTMLImageElement;
"input": HTMLInputElement;
"ins": HTMLModElement;
"kbd": HTMLElement;
"label": HTMLLabelElement;
"legend": HTMLLegendElement;
"li": HTMLLIElement;
"link": HTMLLinkElement;
"main": HTMLElement;
"map": HTMLMapElement;
"mark": HTMLElement;
"marquee": HTMLMarqueeElement;
"menu": HTMLMenuElement;
"meta": HTMLMetaElement;
"meter": HTMLMeterElement;
"nav": HTMLElement;
"noscript": HTMLElement;
"object": HTMLObjectElement;
"ol": HTMLOListElement;
"optgroup": HTMLOptGroupElement;
"option": HTMLOptionElement;
"output": HTMLOutputElement;
"p": HTMLParagraphElement;
"param": HTMLParamElement;
"picture": HTMLPictureElement;
"pre": HTMLPreElement;
"progress": HTMLProgressElement;
"q": HTMLQuoteElement;
"rp": HTMLElement;
"rt": HTMLElement;
"ruby": HTMLElement;
"s": HTMLElement;
"samp": HTMLElement;
"script": HTMLScriptElement;
"section": HTMLElement;
"select": HTMLSelectElement;
"slot": HTMLSlotElement;
"small": HTMLElement;
"source": HTMLSourceElement;
"span": HTMLSpanElement;
"strong": HTMLElement;
"style": HTMLStyleElement;
"sub": HTMLElement;
"summary": HTMLElement;
"sup": HTMLElement;
"table": HTMLTableElement;
"tbody": HTMLTableSectionElement;
"td": HTMLTableDataCellElement;
"template": HTMLTemplateElement;
"textarea": HTMLTextAreaElement;
"tfoot": HTMLTableSectionElement;
"th": HTMLTableHeaderCellElement;
"thead": HTMLTableSectionElement;
"time": HTMLTimeElement;
"title": HTMLTitleElement;
"tr": HTMLTableRowElement;
"track": HTMLTrackElement;
"u": HTMLElement;
"ul": HTMLUListElement;
"var": HTMLElement;
"video": HTMLVideoElement;
"wbr": HTMLElement;
}
document.addEventListener('click', (e: MouseEvent) => {
console.log(e)
})
function primise():Promise<number>{
return new Promise<number>((reslove,reject)=>{
reslove(4)
})
}
promise().then(res=>{
console.log(res)
})
class类
class Tom {
public name: string
private age: number
protected sub: boolean
static nb: string
constructor(name: string, age: number, sub: boolean) {
this.name = name
this.age = age
this.sub = sub
}
static run() {
console.log(this.name)
}
}
let person = new Tom('汤姆', 18, false)
person.name = '班花姐姐'
class Banhua extends Tom {
constructor() {
super('汤姆', 18, false)
this.sub = true
}
}
let banhua = new Banhua()
console.log(banhua);
console.log(person);
Tom.nb = 'nb'
Tom.run()
interface PersonClass {
get(type: boolean): boolean
}
interface PersonClass2 {
set(): void,
asd: string
}
class personClass {
name: string
constructor() {
this.name = 'TOM'
}
}
class sonClass extends personClass implements PersonClass, PersonClass2 {
asd: string
constructor() {
super()
this.asd = '123'
}
get(type: boolean) {
return type
}
set(): void {
}
}
let son = new sonClass()
console.log(son);
abstract class abstractClass {
public name: string
constructor(name: string) {
this.name = name
}
abstract getName(): string
}
class abstractSon extends abstractClass {
constructor() {
super('tom')
}
getName(): string {
return this.name
}
}
let abSon = new abstractSon()
console.log(abSon.getName());