I feel stupid asking this question. But I have an annoying issue with variable scoping aaa below. Shouldn’t it output test at the end? But that wasn’t the case. What did I do wrong to use aaa within a function?
var casper = require('casper').create();
var aaa = 'test';
casper.start('http://google.com/', function() {
this.echo("I'm in");
});
casper.run(function(aaa) {
this.echo(aaa);
this.exit();
});
When you echo out
aaa, it uses theaaaas defined in the first parameter for your function. If your first parameter was calledbbbor something, then you would see the output that you expect, as it would use theaaadefined in the outer closure.