// function fn1() { // } // fn1(); // 立即执行函数 可以进入页面 开始执行 可以保证作用域 名字的唯一性 // (function() {})() (function(){ class Money{ name:string; num: number; constructor(name:string,num:number) { this.name = name; this.num = num; } show(){ console.log(`我是${this.name},我有${this.num}万`); } } /** * 继承: * 因为想让多个子类同时拥有父类的属性和方法 所以采用继承 * 继承后 子类会拥有和父类相同的内容 * 若子类中 定义的方法与父类相同 则会覆盖父类的方法 称为:方法重写 * 若想添加新的方法 直接添加即可 * */ class A extends Money{ show() { console.log("我继承到了") } say() { console.log("你好啊") } } let aa = new A('小红',200); console.log(aa,'aa') aa.show(); aa.say(); })() // extends