Код: Выделить всё
$ nvm exec 22 node
Running node v22.15.1 (npm v10.9.2)
Welcome to Node.js v22.15.1.
Type ".help" for more information.
> const { JSDOM } = require('jsdom');
undefined
> const dom = new JSDOM("");
undefined
> var $ = require('jquery')(dom.window);
undefined
> $.extend
[Function (anonymous)]
> $(dom.window.document)
jQuery {
'0': Document {
location: [Getter/Setter],
[Symbol(SameObject caches)]: [Object: null prototype] {
childNodes: Proxy [Array],
implementation: DOMImplementation {}
}
},
length: 1
}
< /code>
$ nvm exec 22 node
Running node v22.15.1 (npm v10.9.2)
Welcome to Node.js v22.15.1.
Type ".help" for more information.
> const { JSDOM } = require('jsdom');
undefined
> function set_up_globals() {
... // Set up a mock document:
... const dom = new JSDOM("");
... global.window = dom.window;
... global.document = dom.window.document;
... global.navigator = dom.window.navigator;
... global.HTMLElement = dom.window.HTMLElement;
... global.$ = require('jquery')(dom.window);
... }
undefined
> set_up_globals();
undefined
> $.extend
[Function (anonymous)]
> $(document)
Uncaught TypeError: $ is not a function
< /code>
Why is there a TypeErrorПодробнее здесь: https://stackoverflow.com/questions/797 ... in-node-js