ajax-hook
ajax-hook copied to clipboard
fix: events handling
getEventTarget(xhr)
- only
document.createElement('a')
was used. -
document.createDocumentFragment()
would be a better way to create EventTarget since the creation of HTMLElement is slightly higher thanDocumentFragment
-
document.createDocumentFragment()
is well supported in ES5. (just Opera 10-12 is unknown) - No functional affect to the current script.
addEventListener and removeEventListener
-
removeEventListener
was missing, but mentioned inindex.d.ts
-
WeakMap
is used for this particular usage. -
WeakMap
in very old browsers might be not supported, in that case,removeEventListener
is ignored. - No functional affect to the current script.
Minor fix in event handler
- ~changed
event.type = args[0];
toevent.type = e.type;
to avoid memory leakage of arrayargs
.~ the type must be the same as theargs[0]
. assignment not required.
Combined Distribution Script ajaxhook.js
for Testing (PR 119, 120, 121, 122)
https://cdn.jsdelivr.net/gh/cyfung1031/ajax-hook@1ebe48e08108449669290a226e52fc6fbf7ec9ef/dist/ajaxhook.js
这次改动是要解决丢失 removeListener 的问题?
这次改动是要解决丢失 removeListener 的问题?
之前只做了addEventListener,addEventListener跟removeEventListener是一對的 addEventListener裡面的把真正listen的function改了,一般removeEventListener是除掉不了
雖然很少機會會用removeEventListener,但你猜不到原本網站其他的XHR處理是怎樣,不理的話有機會報錯