title: How to implement Javascript CustomEvent IE Polyfill
body: <p>I'm having problems understanding how I should be implementing the IE CustomEvent Polyfill. I have CustomEvent working in other browsers but can't seem to get the Polyfill to work.</p>
  
  <pre><code>(function () {
  
      // CustomEvent polyfill
      // https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent/CustomEvent#Polyfill
      if ( typeof window.CustomEvent === "function" ) return false; //If CustomEvent supported return
  
      function CustomEvent ( event, params ) {
          params = params || { bubbles: false, cancelable: false, detail: undefined };
          var evt = document.createEvent( 'CustomEvent' );
          evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail );
          return evt;
      }
  
      CustomEvent.prototype = window.Event.prototype;
  
      window.CustomEvent = CustomEvent;
  
  
  })();
  
  // CustomEvent supported
  // From example: https://www.kirupa.com/html5/custom_events_js.htm
  
  document.body.addEventListener("fontsLoaded", doSomething, false);
  
  function doSomething(e) {
      alert("Event is called: " + e.type);
  }
  
  var myFontsLoaded = new CustomEvent("fontsLoaded");
  document.body.dispatchEvent(myFontsLoaded);
  </code></pre>