shama / on-load

On load/unload events for DOM elements using a MutationObserver
113 stars 19 forks source link

Make caller argument obligatory #23

Closed aknuds1 closed 7 years ago

aknuds1 commented 7 years ago

The technique for deducing the caller argument to onload is unsound, as Function.caller is disallowed in strict mode and apparently generally considered a bad idea.

This patch makes the caller argument obligatory. However: How should we test that caller is passed? Throw an exception?

Also, if anyone has suggestions for some safe way of auto-generating the caller parameter rather than resorting to Function.caller, that would be great.

Fixes #15

joshgillies commented 7 years ago

Should we also aim to provided updated documentation around why the caller argument is required?

aknuds1 commented 7 years ago

@joshgillies Thanks for the suggestion, I've edited the README.

shama commented 7 years ago

I don't think it should be obligatory. If it was, it would mean everyone using the library would have to agree on unique global names for their elements. I think it's ok to specify your own name, if you really need/want to but it's going to conflict eventually in more complex environments.

Ultimately it should be a build step in production that specifies a for sure unique name and then fall back on Function.caller or another method of your choosing for dev mode. I'm open to other ideas on uniquely identifying a portion of code too or a changing the API so it's not needed somehow.