Re-bind onclick, on* event listeners for debugging

前端 未结 1 525
执念已碎
执念已碎 2021-01-21 19:57

I want to monkeypatch event listener registrations.

I found this answer showing how to do it for addEventListener:

const native         


        
1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-21 20:09

    You can get the original setter function with:

    const originalSetter = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'onchange').set;
    

    If you want to redefine a property, you should look at using Object.defineProperty().

    0 讨论(0)
提交回复
热议问题