mercredi 13 mars 2019

What object, instead of window, has (global) function foo as a property if foo is defined in a javascript file and included from html?

If I place the following code in an html file:

<script>
  function foo()
  {
  }

  alert("foo" in window);
</script>

true is shown in a dialog. (see https://jsfiddle.net/f1t2c3kL/ for example.) But if I move foo's definition to file.js and place

<script type="text/javascript" src="file.js"></script>

in the html header, false is shown instead.

What should I use instead of window so that the alert shows true ?





Aucun commentaire:

Enregistrer un commentaire