3. 支持类实例方法

 

添加类Person3.js 代码如下:

Ext.namespace("Ext.dojochina");

Ext.china_hongzk.Person = Ext.emptyFn; // Ext.emptyFn 等同于function(){};

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

            name: "",//为空的实例属性

            sex: "",//为空的实例属性

            print:function(){   //定义方法为print

               //format方法 功能是参数拼接

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

            }

});然后再在Person3.aspx 页面里调用 Person3.js 代码如下:

<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="Person3.js" type="text/javascript"></script>

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

     var _Person = new Ext.china_hongzk.Person(); //实例对象

        _Person.name = "hongzhikang";

        _Person.sex = "nan";

        _Person.print();

        //再次赋值

        _Person.name = "洪志康";

        _Person.sex = "男";

        _Person.print();

    </script>

</head>

<body>

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

    <div> </div>

    </form>

</body>

</html>

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