I do not understand the behavior of my JavaScript function.
There is a simple function that checks if a URL matches with a RegExp. It returns a boolean.
/**
* Check the url is matching the ProviderURL.
*
* @return {boolean} ProviderURL as RegExp
*/
this.matchURL = function(url) {
return !(this.matchException(url)) && urlPattern.test(url);
};
However, when I call this function, it returns a false in the if-condition, but a true in a console.log.
console.log(providers[i].matchURL(request.url)); //true
if(providers[i].matchURL(request.url)) {
console.log("never displayed.");
}
I have now "fixed" this problem with a previous if-condition. Nevertheless, I would like to know why the program behaves this way.
let match = providers[i].matchURL(request.url);
//really weird method
if(match == providers[i].matchURL(request.url));
if(match)
{
result = removeFieldsFormURL(providers[i], request);
}
It is a WebExtensions addon.
urlPattern:
/**
* Add URL pattern.
*
* @require urlPatterns as RegExp
*/
this.setURLPattern = function(urlPatterns) {
urlPattern = new RegExp(urlPatterns, "mgi");
};