Symbol.searchwhich is used to define the search behavior of objects when used withString.prototype.search.
var SearchSymbol = require( '@stdlib/symbol/search' );Symbol.search which is used to define the search behavior of objects when used with String.prototype.search.
var s = typeof SearchSymbol;
// e.g., returns 'symbol'-
The symbol is only supported in environments which support symbols. In non-supporting environments, the value is
null. -
Symbol.searchdefines the behavior of an object when used byString.prototype.search(). For example, whenstr.search(obj)is called, JavaScript will check for a[Symbol.search]method onobjand call it.
var SearchSymbol = require( '@stdlib/symbol/search' );
function searchFn(str) {
return str.indexOf('foo');
}
var myObj = {};
myObj[ SearchSymbol ] = searchFn;
console.log('foo bar'.search(myObj)); // 0
console.log('bar baz'.search(myObj)); // -1