对官网的例子进行改造
export class Animal {
foo: number;
// ^
// Notice this exclamation point!
// This is the "definite assignment assertion" modifier.
constructor() {
// this.initialize();
}
initialize() {
this.foo = 0;
}
show() {
this.jump(this.foo);
}
jump(a: number) {
console.info(a);
}
}
没有对foo赋值断言,也没有对其初始化,但是this.jump(this.foo)
调用的时候并没有报错,这是为啥?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…