index.js 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. // compatible with NodeList.prototype.forEach() before chrome 51
  2. // https://developer.mozilla.org/en-US/docs/Web/API/NodeList/forEach
  3. if (typeof window === 'object' &&
  4. window.NodeList &&
  5. !NodeList.prototype.forEach) {
  6. NodeList.prototype.forEach = Array.prototype.forEach;
  7. }
  8. // compatible with ParentNode.append() before chrome 54
  9. // https://github.com/jserz/js_piece/blob/master/DOM/ParentNode/append()/append().md
  10. if (typeof window !== 'undefined') {
  11. ;
  12. (function (arr) {
  13. arr.forEach((item) => {
  14. if (Object.prototype.hasOwnProperty.call(item, 'append')) {
  15. return;
  16. }
  17. Object.defineProperty(item, 'append', {
  18. configurable: true,
  19. enumerable: true,
  20. writable: true,
  21. value(...args) {
  22. const docFrag = document.createDocumentFragment();
  23. args.forEach((arg) => {
  24. const isNode = arg instanceof Node;
  25. docFrag.appendChild(isNode ? arg : document.createTextNode(String(arg)));
  26. });
  27. this.appendChild(docFrag);
  28. },
  29. });
  30. });
  31. })([Element.prototype, Document.prototype, DocumentFragment.prototype]);
  32. }
  33. //# sourceMappingURL=index.js.map