Skip to content

Instantly share code, notes, and snippets.

@erdaldalkiran
Created August 27, 2016 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erdaldalkiran/7bda7016a2f48238f2bf68b8207e7533 to your computer and use it in GitHub Desktop.
Save erdaldalkiran/7bda7016a2f48238f2bf68b8207e7533 to your computer and use it in GitHub Desktop.
class MyMatcher {
constructor(value) {
this.value = value;
}
[Symbol.match](string) {
var index = string.indexOf(this.value);
if (index === -1) {
return null;
}
return [`${this.value} altered`];
}
}
console.log('foobar'.match('foo'))
var fooMatcher = 'foobar'.match(new MyMatcher('foo'));
console.log(fooMatcher)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment