| 1234567891011121314151617181920212223242526272829303132333435 |
- // 立即执行函数
- // function fn1() {}
- // fn1()
- // (function () {})()
- (function () {
- // 父级
- class All {
- constructor(name, age) {
- this.name = name;
- this.age = age;
- }
- say() {
- console.log("你好");
- }
- }
- /**
- * 继承:
- * 因为想让多个子类同时拥有父类的属性及方法 所以采用继承
- * 继承后 子类就会拥有父类相同的内容
- * 子类的方法若于父类的方法相同 则会覆盖
- * 若想添加新的方法 直接在子类中添加即可
- */
- class A extends All {
- say() {
- console.log("哈哈");
- }
- back() {
- console.log("撤回");
- }
- }
- let aa = new A('图图', 3);
- console.log(aa);
- aa.say();
- aa.back();
- })();
|