I was reading the book Professional Javascript For Web Developers, and saw the following code. I have some questions about it:
- What does "throw new Error()" return? Undefined?
- What will happen to the code block of "if" if there is an error thrown out?
function matchesSelector(element, selector){
if(element.matchesSelector){
return element.matchesSelector(selector);
}else if(element.msMatchesSelector){
return element.msMatchesSelector(selector);
}else if(element.mozMatchesSelector){
return element.mozMatchesSelector(selector);
}else if(element.webkitMatchesSelector){
return element.webkitMatchesSelector(selector);
}else{
throw new Error("Not supported!");
}
}
if(matchesSelector(document.body, "body.page1")){
//do somthing
}