this
in the top function refers to the global object, because it's called neither as a constructor nor as a method. In a web browser, the global object is window
.
Anyway, assigning a property to the global object allows you to reference it as a global variable. Later on in the code, assert
and test
are available in the onload
function.
So why not just say window.assert = ...
? One reason is that the construction in the code sample is slightly more portable, in case you need to run it in a JavaScript environment where the global object isn't window
.