Is javaScript not part of the DOM?

Why do scripts still function even after the code used to create them is removed from the DOM?

I came across a situation where I wanted to prevent a broken script ( @see my post ) from working.

In an attempt to come up with a solution, I wrote an extension with the following line (just to find out what would happen).

$('script', doc).remove(); /*doc is passed here because this script is running as a firefox extension outside of the document context.*/ 

I assumed that this would remove all scripts from the DOM, which was the case, and therefore no scripts will run on the page, which is not the case.

I would like to know more about what is behind this behavior.

+4
source share
2 answers

The script is part of the DOM, of course, but the result of executing the script is left up to the javascript mechanism. Removing the script source (the part that resides in the DOM) will not delete existing variables in the engine's memory.

+8
source

It is true that Javascript is not part of the DOM (and vice versa). Indeed, at the recent ACM Connections / Reflections conference, I was a guest speaker, the other was Javascript guru Douglas Crockford, and we had interesting chats - I was amazed to learn from him that the committee that is working on standardizing the DOM (in w3c), and the one that works on Javascript standardization (in ECMA) has no coincidences, has no coordination, and actually knows little about each other's existence and work (but, apparently, no more amazed than Crockford himself studied this peculiar fact; -. )

+2
source

Source: https://habr.com/ru/post/1307909/


All Articles