JS: Set.prototype

By Xah Lee. Date: . Last updated: .

New in ES2015.

Set.prototype is the value of the property key "prototype" of the Set object.

〔►see JS: Set Object

console.log( Set.hasOwnProperty ( "prototype" ) ); // true

Type of Set.prototype is object.

〔►see JS: Data Types

// type of Set.prototype
console.log ( typeof Set.prototype === "object" ); // true
console.log ( Object.prototype.toString.call( Set.prototype ) === "[object Set]" ) // true

Parent of Set.prototype is Object.prototype.

// parent of Set.prototype
console.log ( Object.getPrototypeOf ( Set.prototype ) === Object.prototype ); // true

〔►see JS: Prototype and Inheritance

Set.prototype is the parent of all set instances.

console.log ( Object.getPrototypeOf ( new Set() ) === Set.prototype ); // true

The purpose of Set.prototype object is to provides methods and properties useful for all set instances.

Properties


Set.prototype.constructor

Set.prototype.constructor → value is the function object Set.

console.log ( Set.prototype.constructor === Set ); // true
console.log ( (new Set()).constructor === Set ); // true

〔►see JS: Property Key "constructor"

ECMAScript 2015 §Keyed Collection#sec-set.prototype.constructor

Set.prototype.size

set_obj.size → returns the total count of values in set_obj.

size is a getter property. 〔►see JS: Getter/Setter Properties

// size of set
var s = new Set([4, 5, 6]);
console.log(s.size) // 3

ECMAScript 2015 §Keyed Collection#sec-get-set.prototype.size

Set.prototype.add

〔►see JS: Set.prototype.add

Set.prototype.delete

〔►see JS: Set.prototype.delete

Set.prototype.has

〔►see JS: Set.prototype.has

Set.prototype.clear

〔►see JS: Set.prototype.clear

Set.prototype.forEach

〔►see JS: Set.prototype.forEach

Set.prototype.entries

ECMAScript 2015 §Keyed Collection#sec-set.prototype.entries

Set.prototype.keys

ECMAScript 2015 §Keyed Collection#sec-set.prototype.keys

Set.prototype.values

〔►see JS: Set.prototype.values

Set.prototype [ Symbol.iterator ]

〔►see JS: Set.prototype[Symbol.iterator]

Set.prototype [ Symbol.toStringTag ]

〔►see JS: Set.prototype[Symbol.toStringTag]

Reference

ECMAScript 2015 §Keyed Collection#sec-properties-of-the-set-prototype-object

Set Topic

  1. JS: the Set Object Tutorial
  2. JS: Set Union, Intersection, Difference
  3. JS: Set Object
  4. JS: Set.prototype
  5. JS: Set.prototype.forEach
Like what you read? Buy JavaScript in Depth