A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://webplatform.github.io/docs/javascript/Number/prototype below:

prototype · WebPlatform Docs

prototype Summary

Returns a reference to the prototype for a class of number.

Syntax
number.prototype
Examples

The number argument is the name of a 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());
 
 
Remarks

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.

Attributions

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4