JavaScript: Symbol.prototype
New in JS2015.
Symbol.prototype
is the value of the property key "prototype"
of the function Symbol
.
[see Symbol Object]
console.log( Symbol.hasOwnProperty ( "prototype" ) );
Type
Type of Symbol.prototype
is Object
.
console.log(typeof Symbol.prototype === "object"); console.log( Reflect.apply(Object.prototype.toString, Symbol.prototype, []) === "[object Symbol]", );
Parent
Parent of Symbol.prototype
is Object.prototype
.
// parent of Symbol.prototype console.log( Reflect.getPrototypeOf ( Symbol.prototype ) === Object.prototype );
Purpose
Symbol.prototype
is the parent of all symbol objects.
let ss = Symbol(); console.log( Reflect.getPrototypeOf ( Object(ss) ) === Symbol.prototype ); // Object(ss) converts symbol primitive ss to a symbol object
[see Prototype and Inheritance]
Properties
constructor
description
toString
valueOf
[ Symbol.toPrimitive ]
[ Symbol.toStringTag ]
2017-02-10 following is work in progress.
Symbol.prototype.constructor
Symbol.prototype.constructor
-
The value is the object
Symbol
.
console.log( Symbol.prototype.constructor === Symbol );
Symbol.prototype.description
Return the description of the symbol.
Symbol.prototype.toString( )
return a string of the form:
"Symbol(description)"
const x = Symbol("xyz"); console.log( x.toString() === "Symbol(xyz)" );