我有一個問題,利用外部jQuery文件與節點。我有幾個功能,我需要運行,但它不工作。我創建了一個簡單的函數來測試,但是我收到的錯誤消息是TypeError:Object#沒有方法'alert_helloworld'。這裏是我的兩個文件:Node.js與外部jQuery文件
example.js
var jsdom = require('jsdom');
var templateparser = require('./templateparser.js');
var test = templateparser.alert_helloworld();
templateparser.js
function alert_helloworld(){
console.log("Hello World");
return false;
}
HELP !!!!
我不想重塑我的外部文件。我想保持它一樣。這甚至有可能嗎? – user1146581
@ user1146581是/否。您可以將它作爲JavaScript文件注入到jsdom中,或者您可以通過節點中的AST解析器進行注入。否則,不能訪問您在文件中定義的「全局」變量。 – Raynos
所以我想我問,我如何將它作爲JavaScript注入jsdom? – user1146581