js 获取类变量所在的对象
这样向XMLHttpRequest注册函数:doReadyStateChange 后,在doReadyStateChange
中使用this只会得到XMLHttpRequest对象。但是用this.xmlHttpReq.placeObj就可以得
到xmlHttpReq所在的对象!
function RequestInterface(stack, date, type) {
//attributes.
XMLHttpRequest.prototype.placeObj = this;
this.xmlHttpReq;
this.responseData;
//methods.
this.doReadyStateChange = doReadyStateChange;
}
// address must relative address
function requestData(address, requestCmd) {
//alert('requestCmd: ' + requestCmd);
this.xmlHttpReq = new XMLHttpRequest();
this.xmlHttpReq.open("POST", address, true);
this.xmlHttpReq.send(requestCmd);
this.xmlHttpReq.onreadystatechange =
this.doReadyStateChange;
} |
阅读(1684) | 评论(0) | 转发(0) |