UNPKG

@exadel/esl

Version:

Exadel Smart Library (ESL) is the lightweight custom elements library that provide a set of super-flexible components

18 lines (16 loc) 779 B
/** Shim for ES5 style inheritance support of classes in modern browsers */ export function shimES5Constructor(Class: new (...args: any[]) => any): void { if (window.Reflect === undefined || typeof Class !== 'function') return; if (String(Class).indexOf('[native code]') === -1) return; const constructor = function (...args: any[]): any { return Reflect.construct(Class, args, this.constructor); }; Object.defineProperty(constructor, 'name', {value: Class.name}); Object.defineProperty(window, Class.name, {value: constructor}); const Element = (window as any)[Class.name]; Element.prototype = Class.prototype; Element.prototype.constructor = Element; Object.setPrototypeOf(Element, Class); } shimES5Constructor(Event); shimES5Constructor(HTMLElement);