4. 支持类静态方法
添加类Person4.js 代码如下:
Ext.namespace("Ext.china_hongzk");
Ext.china_hongzk.Person = Ext.emptyFn; // Ext.emptyFn 等同于function(){};
Ext.china_hongzk.Person.print = function(_name,_sex){ //定义print类静态方法
var _person = new Ext. china_hongzk.Person();
_person.name = _name;
_person.sex = _sex;
_person.print(); //print类实例方法
}
Ext.apply(Ext.china_hongzk.Person.prototype,{
name: "",
sex: "",
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="Person4.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>