prototype
見上一節,馬克-to-win:prototype作用就是給某個類增加一個實體方法,
例 3.6.2
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
</head>
<script>
/*When the Global object is created, it always has at least the following properties:
Object object Function object Array object String object
Boolean object Number object Date object Math object
Value properties
*/
Array.prototype.mymethod = function(number)
{
var result = -1;
/*注意mymethod功能是找出某數在陣列中出現的位置,作為Array的一個function,可以訪問Array的屬性this.length, 參見上一個prototype的例子,
Student.prototype.infop = function()/*此方法可以為所有Student物件所用*/
{
document.writeln("物件的qixy屬性p:" + this.qixy);
document.writeln("物件的age屬性p:" + this.age);
/*下列話是合法的, 因為不是this.number, 而是Student.number*/
document.writeln("static method is " + Student.number);
};
*/
for (var i = 0; i < this.length; i ++)
{
if (this[i] == number)
{
result = i;
break;
}
}
return result;
}
文章轉載自:https://blog.csdn.net/qq_44594249/article/details/100065974
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/6708.html
標籤:其他
上一篇:JS高級---遞回
下一篇:分享一個博客園皮膚制作腳手架
