zoukankan      html  css  js  c++  java
  • 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>
  • 相关阅读:
    牛客练习赛51 D题
    Educational Codeforces Round 72 (Rated for Div. 2) C题
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) C题
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题
    Codeforces Round #583 (Div. 1 + Div. 2, based on Olympiad of Metropolises) A题
    Educational Codeforces Round 72 (Rated for Div. 2) B题
    Educational Codeforces Round 72 (Rated for Div. 2) A题
    《DSP using MATLAB》Problem 7.2
    《DSP using MATLAB》Problem 7.1
    《DSP using MATLAB》Problem 6.24
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/11285183.html
Copyright © 2011-2022 走看看