node.js - javascript callback closure undefined variable -
I just went something new today. I wanted to use fastenomes in the node and he was establishing the Phantom NPM module. The question is how do you get "document.title". Please take a look at the example code on the site.
How did the document get injection in the callback function? Generally it would pass in the callback as a parameter, but in some way the document is available without passing it through callback parameters
Can anyone explain how it is done? It is also an explanation why someone will do this and not only passes through the parameters?
Various phantom; Phantom = Requirement ('Phantom'); Phantom.create (function (pH) {return ph.create page (function) (return page. Open ("http://www.google.com", function (status) {console.log ("Google opened? Return). Return (); Return page. Evaluate ((function () {return document.title;}), function (result) {console.log ('page title' 'result); return ph.exit ();}) ;});});}); Probably explained in this form, PhantomJS has a special feature where he keeps (makes).
In the global scope window and documents < / Code> objects. Generally, this is the var keyword to any variable. Example
var test = function (cb) {document = 'test'; CB (); } Exam (work () {console.log (document);});
Comments
Post a Comment