Underscore.js is a JavaScript library that provides a lot of useful functions that helps in the programming in a big way like the map, filter, invoke etc. even without using any built-in objects.
The _.matcher() function is an inbuilt function in Underscore.js library of JavaScript which is used to find a predicate function which can inform you if a passed in object includes all the key-value properties that are given in the attrs parameter.
Syntax:
_.matcher(attrs)
Parameters: This function accepts a single parameter as mentioned above and described below:
- attrs: It is the attribute which has a key and a value pair.
Return value: This method returns a predicate function.
Example 1:
Javascript
<!DOCTYPE html> <html>   <head>     <script type= "text/javascript" src= </head>   <body>     <script type= "text/javascript" >         console.log(_.matcher({             picked: true , seeable: false          }));     </script> </body>   </html> |
Output:
function(obj) { return isMatch(obj, attrs); }
Example 2:
Javascript
<!DOCTYPE html> <html> Â Â <head> Â Â Â Â <script type= "text/javascript" Â Â Â Â Â Â Â Â src= </head> Â Â <body> Â Â Â Â <script type= "text/javascript" > Â Â Â Â Â Â Â Â var attr = "neveropen" ; Â Â Â Â Â Â Â Â console.log(_.matcher(attr)); Â Â Â Â </script> </body> Â Â </html> |
Output:
function(obj) { return isMatch(obj, attrs); }
Reference: https://underscorejs.org/#matcher