【发布时间】:2013-09-29 17:27:01
【问题描述】:
如何将 Google 的范围绑定到 fetch_page 函数?我需要能够在 promise-then 链中将函数链接在一起。
Google.prototype.search = function(keyword){
this.keyword = keyword || this.keyword;
fetch_page().then(parse_page).then(function(){
console.log('done');
});
});
function fetch_page(){
// I wants to access google's this.keyword
}
function parse_page(){
// I also wants to access google's this.keyword
}
有什么想法吗?
【问题讨论】:
-
你试过
fetch_page.call(this).then(function (r) { console.log("done"); })吗? -
这是如何将第二个承诺与调用链接起来。(this)。这不会触发功能而不是提供范围吗?
标签: javascript promise