Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Deno have a window object

Tags:

deno

Deno claims to be browser-compatible. Does that mean it has a window / navigator object and what would that mean in terms of things like setting window.location?

like image 659
pguardiario Avatar asked Jan 29 '19 07:01

pguardiario


People also ask

What is the window object?

The window object represents an open window in a browser. If a document contain frames (<iframe> tags), the browser creates one window object for the HTML document, and one additional window object for each frame.

Is window part of the DOM?

The window object is not part of the DOM.

What is window [] in JS?

The window object is globalThe global object of JavaScript in the web browser is the window object. It means that all variables and functions declared globally with the var keyword become the properties and methods of the window object.


1 Answers

The global object in Deno is currently just called window (and globalThis due to upcoming ES standards, sadly). There is currently no navigator/window.location implemented.

The browser-compatible aspects of Deno are aiming to parts that are reasonable to exist even without under the browser environment, e.g. Event, TextEncoder, fetch, etc. It would be an unnecessary burden to implement things like the complete DOM in the Deno core, and such tasks should be delegated to third-party modules (like JSDOM if ported to Deno)

Update: window.location is added in Deno v0.3.0, pointing to the entry file's path (remote or local) (see usage in https://github.com/denoland/deno/issues/1750 , could be useful to implement something similar to Python's if __name__ == "__main__"

like image 95
Kevin Qian Avatar answered Sep 19 '22 11:09

Kevin Qian