2. 支持类实例属性
添加类Person2.js 代码如下:
Ext.namespace("Ext.china_hongzk"); // 声明命名空间
Ext.china_hongzk.Person = function(){}; // Ext.emptyFn 等同于function(){};
Ext. china_hongzk.Person = Ext.emptyFn; // Ext.emptyFn 等同于function(){};
//Ext.apply静态方法的功能:将后面属性name的值赋给原型函数prototype
Ext.apply(Ext.dojochina.Person.prototype,{ // prototype函数原型
name:"hongzhikang" //这里就是属性
});
然后再在Person2.aspx 页面里调用 Person2.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="Person2.js" type="text/javascript"></script>
<script type="text/javascript" language="javascript">
new Ext.china_hongzk.Person(); //命名空间
var _Person = new Ext.china_hongzk.Person(); //实例化一个对象
alert(_Person.name);
_Person.name = "洪志康!";
alert(_Person.name);
</script>
</head>
<body>
<form id="form1" runat="server">
<div> </div>
</form>
</body>
</html>