wiki と同じことをして、SpookyJS で外部関数を呼び出そうとします: https://github.com/WaterfallEngineering/SpookyJS/wiki/Introduction
しかし、次のコードを試すと、次のエラーが発生します。
ReferenceError: 変数が見つかりません: test
try {
var Spooky = require('spooky');
} catch (e) {
var Spooky = require('../lib/spooky');
}
var urls = ["http://www.google.fr",
"http://www.yahoo.com"
];
exports.clicker = function(req, res)
{
console.log("FIRST: " + visitUrl + " \n\n\n END FIRST");
var visitUrl = function(urlIndex, nbClicked)
{
console.log("HELLO");
};
var spooky = new Spooky(
{
child: {
// transport: 'http'
},
casper: {
logLevel: 'debug',
verbose: true
}
}, function (err)
{
if (err)
{
e = new Error('Failed to initialize SpookyJS');
e.details = err;
throw e;
}
spooky.start(urls[0]);
console.log("SECOND: " + visitUrl + " \n\n\n END SECOND");
spooky.then([{
test: visitUrl
}, function(){
console.log("THIRD: " + test + " \n\n\n END THIRD");
}]);
spooky.run();
});
// Uncomment this block to see all of the things Casper has to say.
// There are a lot.
// He has opinions.
spooky.on('console', function (line) {
console.log(line);
});
spooky.on('hello', function (greeting) {
console.log(greeting);
});
spooky.on('log', function (log) {
if (log.space === 'remote') {
console.log(log.message.replace(/ \- .*/, ''));
}
});
}
次の 2 つのログが機能します。
console.log("FIRST: " + visitUrl + " \n\n\n END FIRST");
console.log("SECOND: " + visitUrl + " \n\n\n END SECOND");
しかし、3番目のものはエラーメッセージの原因です:
console.log("THIRD: " + test + " \n\n\n END THIRD");
なにか提案を?