Perhaps as explained in this question and answer, PhantomJS has a special feature where it puts (creates) the window
and document
objects in the global scope.
Generally this is done by assigning something to a variable without using the var
keyword.
Example
var test = function(cb){
document = 'test';
cb();
}
test( function(){
console.log(document);
});