Symbol which provides a method for replacing substrings matched by the current object.
var ReplaceSymbol = require( '@stdlib/symbol/replace' );symbol which provides a method for replacing substrings matched by the current object.
var s = typeof ReplaceSymbol;
// e.g., returns 'symbol'- The symbol is only supported in environments which support symbols. In non-supporting environments, the value is
null. - When calling
String.prototype.replaceandString.prototype.replaceAlland thepatternargument is an object with a[ReplaceSymbol]()method, this method is called with the target string and replacement as arguments.
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' ) );