zoukankan      html  css  js  c++  java
  • JavaScript ES6中的继承

     <script>
    
            /*
            // ES6之前的继承
            function Person(myName, myAge) {
                this.name = myName;
                this.age = myAge;
                this.say = function () {
                    console.log(this.name, this.age);
                };
            }
    
            function Studnt(myName, myAge, myScore) {
                // 通过call函数借用父类的构造函数
                Person.call(this, myName, myAge);
                this.score = myScore;
                this.learn = function () {
                    console.log("day day up");
                };
            }
            // 将子类的原型对象更改为父类的实例对象
            Studnt.prototype = new Person();
            Studnt.prototype.constructor = Studnt;
            let stu = new Studnt("peter", 20, 50);
            stu.say();
            console.log(stu);
            */
    
    
            // ES6中的继承
            class Person{
                constructor(myName, myAge){
                    this.name = myName;
                    this.age = myAge;
                }
    
                say(){
                    console.log(this.name, this.age);
                }
            }
    
            class Student extends Person{
                constructor(myName, myAge, myScore){
                    super(myName, myAge);
                    this.score = myScore;
                }
                learn = function(){
                    console.log("day day up");
                }
            }
    
            let stu = new Student("tm", 12, 100);
            console.log(stu);
            stu.say();
        </script>
    
  • 相关阅读:
    Django之form组件
    Http协议
    用户认证系统 django.contrib.auth模块
    自己关于Django的一些实践
    form标签
    jquery 遍历find()与children()的区别
    存储过程
    ASP.NET优化
    TRUNCATE与 DELETE
    视图的作用
  • 原文地址:https://www.cnblogs.com/TomHe789/p/12722900.html
Copyright © 2011-2022 走看看