const attempt = (fn, ...args) => {
        try {
          return fn(...args);
        } catch (e) {
          return e instanceof Error ? e : new Error(e);
        }
      };
      var elements = attempt(function(selector) {
        return document.querySelectorAll(selector);
      }, '>_>');
      if (elements instanceof Error) elements = []; // elements = []
      
      Javascript language logo

      Attempt Function

      Executes function and returns either true or false based on execution status

      0 Comments

        Add Comment

        Log in to add a comment

        Codiga - All rights reserved 2022.