One of them has been asked by our readers how to write a good user interface for a site that allows you to open and close windows. The code is simple, but I think it is worth explaining for those who are interested in that sort of thing.
If you want to use a web browser, you might be thinking that you want to use window.open() and window.close() from the standard library. However, this is not the case. If you want to use those functions, you need to write your own. You do this by creating a custom window object that inherits from WebWindow. You can then set the appropriate properties on your window, and use events such as window.onclick() and window.
For instance, if you just want to allow someone to use your window object, you can use window.open function and send the data yourself. However, if you want to allow someone to modify the window object’s properties, you can’t do it. The property names are not enough to show what you’re doing. The only way of knowing what you’re doing is to create a custom window object and implement the relevant methods.
window.open function is a bit of a pain. It works just fine until you decide to allow someone to modify the window object properties. It requires you to manually call the functions such as setSize, setLocation, and so on, but you can use the set function to do it for you. There are other ways of doing it, but it is not the easiest solution.
What if we are interested in controlling the size or position of a window? We could use window.setTimeout() instead of window.open() and set the time we give it. This function will call a given function or method with the given timeout every time the window is about to be created. The result of the timeout will be returned from the function or method and the window will only be created if the result is true. The window will be destroyed once the timeout is over.
I’m actually quite surprised that window.setTimeout is not more widely used.
In short, window.setTimeout sets the timeout to be a given time in seconds, and the function or method that is required to be called with the timeout will be called with the timeout as well.
This is a pretty nice, concise way to avoid creating a window. All you have to do is set the timeout to a given time and then call the required method or function.
Sure, it’s not the most elegant way to do it, but it’s pretty neat. I just wish it was more widely used. I suspect it was because it was a bit cumbersome for the language to support other functionality, like window.open being called with a different window object than that of the window that is being opened.