Adventures with WebStorm
WebStorm is a JavaScript IDE recommended to me by Jonathan Beyrak-Lev. I have been playing with it, and I thought it would be entertaining for readers to, in effect, watch the clash in “The Dinosaur Versus the Borg”.
I had no problem getting a project up and running; I had only to paste my existing code into their file. It even preserves the file in standard text format. Nice!
I really like the way that it immediately identifies any problem with the code, including the use of deprecated attributes and infelicitous phrasings. Well, mostly. It frowns upon a construction I used for which there is no proper alternative.
Trouble first began when I attempted to run/debug my code the first time. First it wants to know where my node.js file is. “What’s a node.js file?” I asked. So off I went, rooting around the Internet. It took only a few minutes to learn that a node.js file is an engine that runs JavaScript. Apparently, the creators of WebStorm don’t want to package an engine inside their development environment. This way you get to download all the latest versions as they change. OK, so I downloaded the thing. It automatically installed itself; I have no idea where it installed itself and what price I’ll pay for that. I’m running on trust here.
So with node.js installed, I attempt to run/debug my program. It immediately detects an error that the syntax sniffer built into the editor somehow missed:
let a = document.createElement('a');
ReferenceError: document is not defined
Gee, that’s strange. Everybody else in the world seems to know what ‘document’ means, but apparently not this program. Perhaps this program doesn’t incorporate HTML, which would make it pretty strange. But I searched the Internet and found 6,970 hits, all of them apparently discussing this same problem. Apparently I am the 6,971st person to be baffled by this problem, so I feel that I’m in good company. Here’s a discussion of the problem on StackOverflow.com. Here’s the lead answer that was given to the question:
Stackoverflow.com
It depends on when the self executing anonymous function is running. It is possible that it is running before window.document
is defined.
In that case, try adding a listener
window.addEventListener('load', yourFunction, false);
// ..... or
window.addEventListener('DOMContentLoaded', yourFunction, false); yourFunction () {// some ocde}
Update: (after the update of the question and inclusion of the code)
Read the following about the issues in referencing DOM elements from a JavaScript inserted and run in head
element:
- “getElementsByTagName(…)[0]” is undefined?
- Traversing the DOM
Well, gee, all I have to do now is figure out what a ‘self executing anonymous function’ is. Also, I have to figure out whether my code runs before or after window.document is defined. I have no idea how to do that. I could, of course add a window event listener, but I have no idea where to place this (the problem occurs at the beginning of the code) or what ‘some code’ is. And I’ll also have to consult some other citations in order to understand all this.
Jeez, I feel like I’m being required to learn how to fly a 747 when I just want to run down to the store to get a gallon of milk. Doesn’t ANYBODY have a tricycle?
Well, it looks as if I’m not going to be using WebStorm. It operates on its own, not inside a browser, and that apparently brings in new requirements that I’m not able to satisfy. Nice try. I’ll go back to a smart text editor plus the code handling features built into my browser. I’m not sure, however, which browser provides the best set of debugging tools. So off I go again to the Internet to find out.
Promises
I’ve decided to see how to implement promises. I have written an encounter in which Arthur can make a promise to somebody. Now I must figure out how to implement the resolution of the promise. It would be simple to simply make the resolution of the promise a consequence of the encounter in which the promise was made, but that doesn’t get to the heart of the matter of trust. There must be some time delay between making the promise and fulfilling it. That’s what makes this difficult. How does the system bring the promise back to Arthur to ensure his acting on it? Or should Arthur be required to remember on his own?
This opens up an entirely new can of worms: should Arthur have opportunities to take the initiative? If so, what form should these opportunities take? I suppose that I could have a few encounters in which Arthur has some free time and is give a few options, such as a list of promises to act on, or some initiative to take.
Time for a walk in the forest.
Later…
No luck. I worked in the forest, collecting and piling slash (I’ll probably burn it tomorrow), thinking over the problems. Promises are only meaningful if they are part of some sort of deal. Arthur says something like “Do this for me today and I’ll do that for you tomorrow.” But specifying the this’s and that’s is difficult. Even more important is the problem of bringing up the ‘that’ part. It would work if we specified a due date for the promise. In other words, “I’ll gladly pay you Tuesday for a hamburger today.” But can I assemble a broad collection of promises like that?
Grumble, mumble...