Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js promisify in browser

function promisify(func, callbackPos=null) {
  return (...args) => {
    return new Promise((resolve) => {
      const cb = (...args) => {
        resolve(args);
      };
      args.splice(callbackPos != null ? callbackPos : args.length, 0, cb);
      func(...args);
    });
  };
};
 
PREVIOUS NEXT
Tagged: #js #promisify #browser
ADD COMMENT
Topic
Name
4+3 =