Sunday 15 March 2015

javascript - ReferenceError: Can't find variable with SpookyJS -


I try to make an external function call in Spokijs by doing the same thing to the wiki:

But when I try the following code, I get this error:

Reference error: Can not find variable: test

 < Code> try {var spooky = required ('scary'); } Hold (e) {var spoky = ('../ lib / spooky'); } Var urls = ["http://www.google.fr", "http://www.yahoo.com"]; Export.clicker = function (req, res) {console.log ("First:" + visitUrl + "\ n \ n \ n Last in the end"); Var visitUrl = function (urlIndex, nbClicked) {console.log ("hello"); }; Var spooky = new spooky ({child: {/ transport: 'http'}, Casper: {logLevel: 'debug', verbose: true}}, function (mistake) {if (err) {e = new error ('spookies Failed to initialize s); id description = fault; throw a;} spooky. Start (url [0]); console.log ("second:" + url + "\ n \ n \ n on the other side"); Spooky.then ([{test: visitUrl}, function () {console.log ("THIRD:" + test + "\ n \ n \ n end THIRD");}]); spooky.run ();}) ; // Remove this block to see all the things that Casper has to say. // it is enough. // That opinion is Spooky.on ('console', function (line) {console.log (line);}); Spooky.on ('Hello', Function (greeting) {console.log;}); Spooky.on ('log', function (log) {if (log space === 'remote') {console.log (log. Message.replace (/ \ -. * /, ''))}}} ); }  

These two following logs work:

  console.log ("First:" + visitUrl + "\ n \ n \ n Finally first") ; Console.log ("SECOND:" + visitUrl + "\ n \ n \ nOther seconds");  

But the third error is responsible for the message:

  console.log ("THIRD:" + test + "\ n \ n \ nAnd third ");  

Any suggestions?

Instead of giving a big answer, I would like to comment on your post but I do not have a reputation for it. , Meh

You can not work in the etching if you want to

  var x = 'helo' spooky.then ([{XinCasper: x}, function () {// do something with XinCasper}])  

This will work if you want to pass an object or array, then use JSON.stringify and rebuild it in Casper Scope .

If you want to use spooky function from a mutually scope, use event emitters instead (see most of the last lines):

  Try {var Spooky = essential ('scary'); } Hold (e) {var spoky = ('../ lib / spooky'); } Var urls = ["http://www.google.fr", "http://www.yahoo.com"]; Export.clicker = function (req, res) {console.log ("First:" + visitUrl + "\ n \ n \ n Last in the end"); Var visitUrl = function (urlIndex, nbClicked) {console.log ("hello"); }; Var spooky = new spooky ({child: {/ transport: 'http'}, Casper: {logLevel: 'debug', verbose: true}}, function (mistake) {if (err) {e = new error ('spookies Failed to initialize s); id description = fault; throw a;} spooky. Start (url [0]); console.log ("second:" + url + "\ n \ n \ n on the other side"); Spooky.then (function () {// Casper scope var y = 'some' this.emit ('third', y)}); spooky.run ();}); Spooky.on ('third', function (y) {console.log ('hey, I can' + y + 'output.')}}  

No comments:

Post a Comment