A RetroSearch Logo

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

Search Query:

Showing content from http://www.w3schools.com/jsref/jsref_prototype_boolean.asp below:

Website Navigation


JavaScript Boolean prototype Constructor

JavaScript Boolean prototype Example

Make a new method for JavaScript booleans:

Boolean.prototype.myColor = function() {
  if (this.valueOf() == true) {
    return "green";
  } else {
    return = "red";
  }
};

Create a boolean, then call myColor():

let a = true;
let color = a.myColor();

Try it Yourself » Description

prototype allows you to add new properties and methods to booleans.

prototype is a property available with all JavaScript objects.

Syntax

Boolean.prototype.name = value

Warning

You are not advised to change the prototype of an object that you do not control.

You should not change the prototype of built in JavaScript datatypes like:

Only change the prototype of your own objects.

The prototype Property

The JavaScript prototype property allows you to add new properties to objects:

Example

function Person(first, last, age, eyecolor) {

this.firstName = first;

this.lastName = last;

this.eyeColor = eyecolor;

}

Person.prototype.nationality = "English";

Try it Yourself » Browser Support

prototype is an ECMAScript1 (JavaScript 1997) feature.

It is supported in all browsers:

Chrome Edge Firefox Safari Opera IE Yes Yes Yes Yes Yes Yes

Track your progress - it's free!


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