prototype 属性 (Number)
为number的类返回原型的引用。
语法
number.prototype
备注
number参数是数字的名称。
Use the prototype
property to provide a base set of functionality to a class of objects. New instances of an object "inherit" the behavior of the prototype assigned to that object.
For example, to add a method to the Number
object that returns the number of (integer) digits, declare the function, add it to Number.prototype
, and then use it.
function number_digits() { var digits = 0; var num = this; while (num) >= 1) { digits++; num /= 10; } return digits; } Number.prototype.digits = number_digits; var myNumber = new Number(3456.789); document.write(myNumber.digits()); // Output: // 4
All intrinsic JavaScript objects have a prototype
property that is read-only. Properties and methods may be added to the prototype, but the object may not be assigned a different prototype. However, user-defined objects may be assigned a new prototype.
The method and property lists for each intrinsic object in this language reference indicate which ones are part of the object's prototype, and which are not.
必备条件
在以下文档模式中受支持:怪异模式、Internet Explorer 6标准模式、Internet Explorer 7标准模式、Internet Explorer 8标准模式、Internet Explorer 9标准模式、Internet Explorer 10标准模式、Internet Explorer 11标准模式。应用商店应用(Windows 8和Windows Phone 8.1)中也受支持。请参阅版本信息。