|
@@ -0,0 +1,37 @@
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+(function () {
|
|
|
+ class Money {
|
|
|
+ constructor(name, num) {
|
|
|
+ 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();
|
|
|
+})();
|
|
|
+
|