我有一个看起来像这样的代码:
function program(){
this.bye = function(){
//some code
return this;
}
this.hello = function(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(geoSuccess,geoError);
}
return this;
}
if(this instanceof program()){
return this.program;
} else {
return new program();
}
}
var PR = new program();
我的问题是:如何完成链执行,例如:
TB.hello().bye();
并在地理定位响应到达时执行 bye()。
我想保持链执行,而不必从 geoSuccess 函数内部执行 .bye() 。有没有办法做到这一点?