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>
  • 相关阅读:
    spring bean的作用域
    Web前端开发CSS规范总结
    前端技术都包含哪些?
    Web安全常见问题及解决方法
    如何让手游更省带宽,耗电量更少?TBR渲染架构解析!
    新手学Java,有哪些入门知识点?
    如何让手游内存占用更小?从内存消耗iOS实时统计开始
    动作游戏老是卡?试试从这些方面提升流畅度
    开发者必知!2020年大前端发展趋势解读
    游戏编程入门! 想成为专业的游戏开发程序员需要掌握哪些?
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/11285183.html
Copyright © 2011-2022 走看看