Skip to content

Latest commit

 

History

History
 
 

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

README.md

ReplaceSymbol

Symbol which provides a method for replacing substrings matched by the current object.

Usage

var ReplaceSymbol = require( '@stdlib/symbol/replace' );

ReplaceSymbol

symbol which provides a method for replacing substrings matched by the current object.

var s = typeof ReplaceSymbol;
// e.g., returns 'symbol'

Notes

  • The symbol is only supported in environments which support symbols. In non-supporting environments, the value is null.
  • When calling String.prototype.replace and String.prototype.replaceAll and the pattern argument is an object with a [ReplaceSymbol]() method, this method is called with the target string and replacement as arguments.

Examples

var defineProperty = require( '@stdlib/utils/define-property' );
var ReplaceSymbol = require( '@stdlib/symbol/replace' );

function replace( str, replacement ) {
    return replacement;
}

var obj = {};

defineProperty( obj, ReplaceSymbol, {
    'configurable': true,
    'value': null
});

var str = 'beep';
console.log( str.replace( obj, 'boop' ) );

defineProperty( obj, ReplaceSymbol, {
    'configurable': true,
    'value': replace
});
console.log( str.replace( obj, 'boop' ) );