68-继承方式二

2019-04-27  本文已影响0人  仰望_IT
        function Person(myName, myAge) {
            // let per = new Object();
            // let this = per;
            // this = stu;
            this.name = myName; // stu.name = myName;
            this.age = myAge;   // stu.age = myAge;
            this.say = function () {    // stu.say = function () {}
                console.log(this.name, this.age);
            }
            // return this;
        }
        function Student(myName, myAge, myScore) {
            // let stu = new Object();
            // let this = stu;

            // 通过call修改this和传参
            Person.call(this, myName, myAge); // Person.call(stu);
            this.score = myScore;
            this.study = function () {
                console.log("day day up");
            }
            // return this;
        }
        let stu = new Student("ww", 19, 99);

        console.log(stu.score);  // 99
        stu.say();  // ww 19
        stu.study();  // day day up
上一篇下一篇

猜你喜欢

热点阅读