• ExtJS的namespace、js的公私有方法和属性


    Ext的namespace和java的namespace是同一个概念。Ext在对类进行定义的时候如果先前的包是不存在的则不能进行类定义。 具体说明在代码中都有注释。

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
      <head>
        <title>04_namespace.html</title>
       
        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="content-type" content="text/html; charset=UTF-8">
       
        <!--<link rel="stylesheet" type="text/css" href="./styles.css">-->
        <script type="text/javascript" src="../ext4/ext-all-debug.js"></script>
        <script type="text/javascript">
            Ext.onReady(function() {赛尔号里的丽莎布布配招
                Ext.namespace("com.tiantian.test");//声明一个namespace,命名空间
                com.tiantian.test.User = function(config) {//定义一个对象
                //对象中的所有公共属性和方法都要使用this关键字来定义,如定义属性name,则有this.name=""
                    if (config) {//当指定了config对象的时候执行该语句
                        this.address = config.address;//通过参数给属性赋值
                    } else {
                        this.address = "";
                    }
                    //定义一个公共属性
                    this.name = "张三";
                    //定义一个私有属性
                    var name2 = "私有属性";
                    this.email = "test@test.com";//默认属性
                    this.now = function() {
                        alert(new Date().toLocaleString());
                    }
                    //定义带有返回值的公共方法
                    this.getName = function() {
                        alert(getName2());
                        return this.name;
                    }
                    var getName2 = function() {
                    //对于私有变量是不能使用this关键字进行访问的
                        return name2;
                    }
                };
                var user = new com.tiantian.test.User({address: "湖南"});
                //新建对象后再往其中添加属性
                Ext.apply(user,{
                    name: "zhangsan",//这个name属性会覆盖前面默认的那个name
                    username: "zhangsanusername",
                    password: "zhangsanpassword"
                });
                //alert(user.name);
                //alert(user.address+"      "+user.email);
                //alert(user.now);
                //user.now();//调用对象的方法
                var n = user.getName();
                alert(n);
            });
        </script>

      </head>
     
      <body>
        This is my HTML page. <br>
      </body>
    </html>

  • 相关阅读:
    win7安装mysql解压缩版
    PCA原理
    通俗理解协方差
    python GIL
    yield理解
    python super 的正确理解
    python常见面试题
    python 的特殊方法 __str__和__repr__
    springMvc REST 请求和响应
    Math.Round 四舍五入问题 解惑 !
  • 原文地址:https://www.cnblogs.com/sky7034/p/2077281.html
Copyright © 2020-2023  润新知