I am trying to write some DOM-parsing code to run from a node REPL environment. Below is a SSCCE:
"use strict";
var jsdom = require("jsdom");
var html="<a></a>";
function parse(html, x) {
jsdom.env(html, function(errors, window) {
x.window = window;
});
}
var x = {};
parse(html, x);
console.log(x.window);
The idea being that after calling the parse
function I would have the parsed DOM available in my x
object.
When I put the above code in a file j.js
and load it from the REPL I get:
> .load j.js
> "use strict";
'use strict'
> var jsdom = require("jsdom");
undefined
> var html="<a></a>";
undefined
> function parse(html, x) {
... jsdom.env(html, function(errors, window) {
..... x.window = window;
..... });
... }
undefined
> var x = {};
undefined
> parse(html, x);
undefined
> console.log(x.window);
undefined
undefined
>
Why does the code fail to assign the x.window
property?