javascript
javascript王者归来--属性和方法的类型
?????? 例21.3 類型的四種屬性
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Example 21.3</title>
</head>
<body>??
<h1 id="output"></h1>
<script language="javascript" type="text/javascript">?
<!--
?????? function dwn(s)
?????? {
????????????? document.write(s + "<br/>");
?????? }
?????? function myClass()
?????? {
????????????? var p = 100;? //private property; 私有屬性
????????????? this.x = 10;? //dynamic public property 動態公有屬性
?????? }
?????? myClass.prototype.y = 20; //static public property or prototype property 原型屬性
?????? myClass.z = 30;? //static property //靜態屬性
?????? var a = new myClass();
?????? dwn(a.p);? //undefined 私有屬性對象無法訪問到
?????? dwn(a.x);?? //10? 公有屬性
?????? dwn(a.y);?? //20? 公有屬性
?????? a.x = 20;
?????? a.z = 40;
?????? dwn(a.x);??? //20?
?????? dwn(a.y);??? //40? //動態公有屬性y覆蓋了原型屬性y
?????? delete(a.x);
?????? delete(a.y);
?????? dwn(a.x);??? //undefined? 動態公有屬性x被刪除后不存在
?????? dwn(a.y);??? //20? 動態公有屬性y被刪除后還原為原型屬性y
?????? dwn(a.z);??? //undefined 類屬性無法通過對象訪問
?????? dwn(myClass.z);? //30 類屬性應該通過類訪問
-->
</script>?
</body>??
</html>
轉載于:https://www.cnblogs.com/xinzhuangzi/archive/2010/06/07/4100587.html
總結
以上是生活随笔為你收集整理的javascript王者归来--属性和方法的类型的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Eclipse+MyEclipse+To
- 下一篇: 深入掌握JMS(六):消息头