5. 支持构造方法

 

添加类Person5.js 代码如下:

Ext.namespace("Ext.china_hongzk");

Ext.china_hongzk.Person = function(_cfg){

    Ext.apply(this,_cfg);

};

Ext.china_hongzk.Person.print = function(_name,_sex){

    var _person = new Ext.china_hongzk.Person({name:_name,sex:_sex});

    _person.print();

}

Ext.apply(Ext.china_hongzk.Person.prototype,{

    print:function(){

    alert(String.format("xingming:{0},xingbie:{1}",this.name,this.sex));

    }

});<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>构造方法</title>

    <link rel="stylesheet" type="text/css" href="../ext-2.0.2/resources/css/ext-all.css" />

    <script src="../ext-2.0.2/adapter/ext/ext-base.js" type="text/javascript"></script>

    <script src="../ext-2.0.2/ext-all.js" type="text/javascript"></script>

    <script src="Person5.js" type="text/javascript"></script>

    <script type="text/javascript" language="javascript">

     Ext.china_hongzk.Person.print("hongzhikang ","nan");

     Ext.china_hongzk.Person.print("洪志康","男");

    </script>

</head>

<body>

    <form id="form1" runat="server">

    <div> </div>

    </form>

</body>

</html>

posted @ 2009-03-31 09:13  hongzk  阅读(173)  评论(0编辑  收藏  举报