我写了三个函数如下。我把amp.js和dish.js放在一个包里。
amp.js:
var amp = (function() {
//return ("This is a message from the demo package");
function amp(){
this.id=10;
}
amp.prototype.display=function(){
return 'value of id is';
}
}());
exports.amp =amp;
dish.js:
var cc=require('./amp');
exports.amp=cc.amp;
EX.js:
var builder = require('botbuilder');
var just=require('JUST');
console.log(just);
var amp= new just.amp();
console.log(amp);
//var ww=new builder.ConsoleConnector();
// Create bot and bind to console
var connector = new builder.ConsoleConnector().listen();
var bot = new builder.UniversalBot(connector);
bot.dialog('/', function(session){
session.send("hello this is chat bot");
//session.send("string returned from the %s",just.amp.display);
});
在EX.js中我试图将amp.js作为类构造函数访问,我收到以下错误,
E:\bot-prac\EX.js:4
var amp= new just.amp();
^
TypeError: just.amp is not a function
at Object.<anonymous> (E:\bot-prac\EX.js:4:10)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:974:3