Sunny-117 / js-challenges

✨✨✨ Challenge your JavaScript programming limits step by step

Home Page:https://juejin.cn/column/7244788137410560055

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

封装remove child.remove()销毁自身

Sunny-117 opened this issue · comments

commented
封装remove child.remove()销毁自身
Element.prototype._remove = function () {
  if (!(this instanceof Element) || this.tagName === 'HTML') {
    throw new TypeError(`${this} is not an element or cannot be removed`);
  }
  const el = this;
  el.parentElement.removeChild(el);
}