javascript - Access parameter of Node.js module function -
im totally new node.js , couldn't find similar question problem. i'm sure it's easy solve 1 of u guys... @ least guess.
i'm trying special paragraph of wikipage using npm mediawiki module node.js! paragraph using pre-defined function following:
bot.page(title).complete(function (title, text, date) { //extract section '== check ==' wikipage&clean string var result = s(text).between('== check ==', '==').s; });
thats working. want is: use "result" outside of code block in other functions. think has callbacks im not sure how handle pre-defined function mediawiki module.
the example function of module wikipage looks following:
/** * request content of page title * @param title title of page * @param ispriority (optional) should request added top of request queue (defualt: false) */ bot.prototype.page = function (title, ispriority) { return _page.call(this, { titles: title }, ispriority); };
which uses following function of module:
function _page(query, ispriority) { var promise = new promise(); query.action = "query"; query.prop = "revisions"; query.rvprop = "timestamp|content"; this.get(query, ispriority).complete(function (data) { var pages = object.getownpropertynames(data.query.pages); var _this = this; pages.foreach(function (id) { var page = data.query.pages[id]; promise._oncomplete.call(_this, page.title, page.revisions[0]["*"], new date(page.revisions[0].timestamp)); }); }).error(function (err) { promise._onerror.call(this, err); }); return promise; }
there's complete callback function , dont know how use it:
/** * sets complete callback * @param callback function call on complete */ promise.prototype.complete = function(callback){ this._oncomplete = callback; return this; };
how can access "result" variable using callbacks outside function of module? don't know how handle callback pre-defined function of module...
what want is: use "result" outside of code block in other functions.
you can't. need use result inside code block (that code block called callback
function btw.). can still pass them other functions, need inside callback function:
bot.page(title).complete(function (title, text, date) { //extract section '== check ==' wikipage&clean string var result = s(text).between('== check ==', '==').s; other_function(result); // <------------- how use });
Comments
Post a Comment