zoukankan      html  css  js  c++  java
  • Ext OOP基础

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>第三章:Ext OOP基础</title>
        <link rel="stylesheet" href="src/ext/resources/css/ext-all.css">
    
        <!--ext-base 必须在ext-all之前引入-->
        <script src="src/ext/ext-base.js"></script>
        <script src="src/ext/ext-all.js"></script>
        <!--<script src="src/ext/ext-lang-zh_CN.js"></script>-->
    </head>
    <body>
    
    <script>
        // js prototype扩展类功能
        var Crab = function () {
            this.legs = 10;
        };
        Crab.prototype = {
            say: function () {
                console.log('我是一只螃蟹,我有' + this.legs + '只脚,横行霸道是我的天性');
            },
        };
        // js继承
        var extend = function (child, father) {
            child.prototype = father.prototype;
        };
        var GenGrab = function () {
            this.legs = 2;
        };
        extend(GenGrab, Crab);
        var gc = new GenGrab();
        gc.say();
    
    </script>
    
    <script>
        /*Ext.namespace('com.aptech') 命名空间*/
        Ext.namespace('com.aptech');
    
        com.aptech.First = function () {
            // 私有成员
            var kiss = '中华人民共和国';
            // 私有方法
    
            // 公有方法
            return {
                // 公有成员
                init: function () {
                    alert('init');
                    alert(kiss);
                },
    
                // 公有成员
                method: function () {
                    alert('method');
                },
            };
        };
    
        com.aptech.Second = function () {
            // 调用父类构造方法
            com.aptech.Second.superclass.constructor.apply(this);
        };
    
        /*
        * @extend 第一个参数子类,第二个参数父类,第三个参数要覆盖的属性
        * com.aptech.Second 子类继承自父类 com.aptech.First
        * */
        Ext.extend(com.aptech.Second, com.aptech.First, {
            // 新方法
            fun: function (i) {
                return i * i * i;
            },
            // 重写com.aptech.First的方法
            method: function () {
                alert('Second::method')
            }
        });
        // 测试
        var second = new com.aptech.Second()
        // alert(second.fun(5))
    
    
        /*
        * Ext.apply() 将第二个参数的成员赋给第一个参数
        * 不管config里面有多少个成功都没问题
        * */
        function Student (config) {
            // 把调用函数的所有属性,
            Ext.apply(this, config)
        }
        var student = new Student({name:'陈大大', sex: '男'})
        console.log('姓名:'+ student.name)
    
        /*
         * Ext.applyIf() 不会将config和obj参数同名属性覆盖,
         * 且obj没有的,config中有,则会被复制到obj中
         * */
        function Student (config) {
            // 把调用函数的所有属性,
            this.name = '陈帅'
            this.sex = '男'
            Ext.applyIf(this, config)
        }
        var student = new Student({name:'陈大大', sex: '男', birthday: new Date()})
        console.log(student)
    </script>
    </body>
    </html>
    

      

  • 相关阅读:
    解决文字溢出,换行等问题
    js获取年、月、日、时、分、秒
    JQuery EasyUI DataGrid动态合并单元格
    JQuery EasyUI Combobox联动
    JQuery EasyUI 读取设置input
    JQuery EasyUI DataGrid获取当前行索引及快速清空
    jQuery EasyUI combobox多选及赋值
    JQuery EasyUI DataGrid 、tree查询
    HTML元素ID和Name区别
    JQuery EasyUI之DataGrid列名和数据列分别设置不同对齐方式(转)
  • 原文地址:https://www.cnblogs.com/hpx2020/p/10762854.html
Copyright © 2011-2022 走看看