• JS 面向对象


    面向对象

    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8" />
        <title>JS面向对象</title>
    </head>
    <body>
        <script>
            //var person = {
            //    name: "jack",
            //    age: 30,
            //    eat: function () {
            //        alert("can eat");
            //    }
            //}
            //alert(person.name);
        </script>
        <script>
            //function Person() {
    
            //}
            //Person.prototype = {
            //    name: "jack",
            //    age: 30,
            //    eat: function () {
            //        alert("can eat");
            //    }
            //}
            //var p = new Person();
            //p.eat();
        </script>
        <script>
            //function People(name) {
            //    this._name = name;
            //}
            //People.prototype.say = function () {
            //    alert("peo-hello" + this._name);
            //}
            //function Student(name) {
            //    this._name = name;
            //}
            //Student.prototype = new People();
            //var superSay = Student.prototype.say;
            //Student.prototype.say = function () {
            //    superSay.call();
            //    alert("stu-hello" + this._name);
            //}
            //var s = new Student("jack");
            //s.say();
    
        </script>
        <script>
            //(function () {
            //    var n = "n";
            //    function People(name) {
            //        this._name = name;
            //    }
            //    People.prototype.say = function () {
            //        alert("peo-hello " + this._name + " " + n);
            //    }
            //    window.People = People;
            //}());
            //(function () {
            //    function Student(name) {
            //        this._name = name;
            //    }
            //    Student.prototype = new People();
            //    var superSay = Student.prototype.say;
            //    Student.prototype.say = function () {
            //        superSay.call(this);
            //        alert("stu-hello " + this._name);
            //    }
            //    window.Student = Student;
            //}())
            //var s = new Student("jack");
            //s.say();
        </script>
        <script>
            //function Person(name) {
            //     var _this = {};
            //     _this._name = name;
            //     _this.sayHello = function () {
            //         alert("p hello " + _this._name);
            //     }
            //     return _this;
            // }
            // function Teacher(name) {
            //     var _this = Person(name);
            //     var surperSay = _this.sayHello;
            //     _this.sayHello = function () {
            //         surperSay.call(_this);
            //         alert("t hello " + _this._name);
            //     }
            //     return _this;
            // }
            // var t = Teacher("jack");
            // t.sayHello();
        </script>
        <script>
            (function () {
                var n = "n";
                function Person(name) {
                    var _this = {};
                    _this._name = name;
                    _this.sayHello = function () {
                        alert("p hello " + _this._name + " " + n);
                    }
                    return _this;
                }
                window.Person = Person;
            })
            function Teacher(name) {
                var _this = window.Person(name);
                var surperSay = _this.sayHello;
                _this.sayHello = function () {
                    surperSay.call(_this);
                    alert("t hello " + _this._name);
                }
                return _this;
            }
            var t = Teacher("jack");
            t.sayHello();
        </script>
    </body>
    </html>
  • 相关阅读:
    超神头文件
    世界上还有比二分更容易错的算法吗?
    【POJ 1734】Sightseeing trip
    P1303 A*B Problem
    P1601 A+B Problem(高精)
    P1051 谁拿了最多奖学金
    【P1025】数的划分
    P1005 矩阵取数游戏
    P1006 传纸条
    邮票问题
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/11285183.html
Copyright © 2020-2023  润新知