[英]Using external modules within AppJs and nodejs
我已经使用AppJS / NodeJS和edge构建了一个基本的演示应用程序。
这是app.js配置文件的相关部分-基本上,它仅引用外部模块。
.......
window.on('ready', function(){
console.log("Window Ready");
window.process = process;
window.module = module;
window.dns = require('native-dns');
window.edge = require('edge');
window.fs = require('fs');
window.frame.openDevTools();
..........
以下是index.html主页中相关的javascript部分:
.......
function myFunction1()
{
var question = dns.Question({
name: 'www.google.com',
type: 'A'
});
var req = dns.Request({
question: question,
server: { address: '8.8.8.8', port: 53, type: 'udp' },
timeout: 1000
});
req.on('timeout', function () {
console.log('Timeout in making request');
});
req.on('message', function (err, answer) {
answer.answer.forEach(function (a) {
console.log(a.address);
});
});
req.on('end', function () {
console.log('Finished processing request');
});
req.send();
}
function myFunction2()
{
var helloWorld = edge.func('async (input) => { return ".NET Welcomes " + input.ToString(); }');
helloWorld('JavaScript', function (error, result) {
if (error) throw error;
console.log(result);
});
}
..........
如果我调用使用另一个nodejs模块(DNS查找)的myFunction1(),则它可以正常工作。 但是,如果我调用使用edge的myFunction2(),则会出现以下错误!
Uncaught TypeError: Property 'func' of object [object Object] is not a function
我已经花了几个小时了,因为无法弄清为什么会这样!
您是否尝试过在app.js中(即在nodejs中)运行相同的myFunction2代码? 可能func函数在边缘对象上不存在。 检查文档,也许您需要执行诸如window.edge = require('edge')。Edge;之类的操作。
或类似的东西来掌握您目前认为的物体。 您还可以执行console.log(window.edge)并查看其输出(在节点和运行开发工具(F12)的浏览器中)。
/西蒙
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.