> Le 10 nov. 2016 à 14:59, Angel Scull <[email protected]> a écrit : > > Hello, > > I’ve tried this code and seems that there is some weird type checking > somewhere that causes this exception. > > TypeError: Method RegExp.prototype.exec called on incompatible receiver > [object Object] > > > let pattern = > /^[a-zA-Z0-9\-\._]+@[a-zA-Z0-9\-_]+(\.?[a-zA-Z0-9\-_]*)\.[a-zA-Z]{2,3}$/; > > let patternProxy = new Proxy(pattern,{}); > > patternProxy.test('[email protected]')
This is because the `exec` method of `pattern` is internally called with `patternProxy` as its receiver (i.e, its "this argument"), and `patternProxy` is not a regexp. This is a general issue with proxies, and not a bug. A simple adhoc workaround is to bind the `exec` method of that particular `pattern` to `pattern` itself: ```js pattern.exec = pattern.exec.bind(pattern) ``` —Claude _______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

