Skip to content

Latest commit

 

History

History
121 lines (70 loc) · 2.99 KB

File metadata and controls

121 lines (70 loc) · 2.99 KB

SearchSymbol

Symbol.search which is used to define the search behavior of objects when used with String.prototype.search.

Usage

var SearchSymbol = require( '@stdlib/symbol/search' );

searchSymbol

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'

Notes

  • The symbol is only supported in environments which support symbols. In non-supporting environments, the value is null.

  • Symbol.search defines the behavior of an object when used by String.prototype.search(). For example, when str.search(obj) is called, JavaScript will check for a [Symbol.search] method on obj and call it.

Examples

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