Google의 범위를 fetch_page 함수에 바인딩하는 방법은 무엇입니까? 나는 약속에서 사슬을 잇는 기능을 함께 할 수 있어야합니다.프로토 타입, 범위 및 약속
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(keyword).then(function() {
parse_page(keyword);
}).then(function(){
console.log('done');
});
을 다음 두 개의 외부 함수의 매개 변수 목록에 keyword
를 추가 :이
var google = new Google(); // return the class instance
google.keyword // get the public class variable called keyword
당신이'fetch_page.call (이) 그 때는 봤어 (기능 (R) {을 console.log ("완료를");})'? –
전화로 두 번째 약속을 연결하는 방법입니다 (this). 범위를 제공하는 대신 기능을 트리거하지 않습니까? – lededje