Created
September 25, 2017 21:04
-
-
Save mistercoffee66/3f9c6771233836cb7774ec9706637364 to your computer and use it in GitHub Desktop.
frequently used polyfills
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Element.matches() | |
if (!Element.prototype.matches) | |
Element.prototype.matches = | |
Element.prototype.msMatchesSelector || | |
Element.prototype.webkitMatchesSelector | |
// NodeList.forEach() | |
if (window.NodeList && !NodeList.prototype.forEach) { | |
NodeList.prototype.forEach = function (callback, thisArg) { | |
thisArg = thisArg || window; | |
for (var i = 0; i < this.length; i++) { | |
callback.call(thisArg, this[i], i, this) | |
} | |
} | |
} | |
// CustomEvent() | |
if ( typeof window.CustomEvent === "function" ) return false | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment