prototype屬性可以將屬性和方法添加到您的Number對象。
注意:prototype是一個全局屬性,幾乎所有對象(數(shù)字,數(shù)組,字符串和日期等)都可用。
Number.prototype.name = value
創(chuàng)建一個新的數(shù)字方法,該方法返回數(shù)字的雙精度值:
Number.prototype.getTwice = function() { return (this.valueOf() * 2); };
對數(shù)字使用新方法:
var a = 25; var b = a.getTwice();// 調用新方法
所有瀏覽器完全支持prototype屬性:
屬性 | ![]() | ![]() | ![]() | ![]() | ![]() |
prototype | 是 | 是 | 是 | 是 | 是 |