确实是this 作用域问题.
BBB.js
sendHttp: function (command, dto, callback) {
this.response = callback;
var xhr = cc.loader.getXMLHttpRequest();
this.httpResponse(xhr);
...
xhr.send(dto.toString());
},
httpResponse: function ( xhr, responseHandler ) {
var handler = responseHandler || function (response) {
return "POST" + " Response (30 chars): " + response.substring(0, 30) + "...";
};
// Simple events
['loadstart', 'abort', 'error', 'load', 'loadend', 'timeout'].forEach(function (eventname) {
xhr["on" + eventname] = function () {
cc.log("eventname : " + eventname);
};
});
// Special event
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && (xhr.status >= 200 && xhr.status < 300)) {
this.response(xhr.responseText);
} else {
//cc.log(xhr.responseText);
}
};
}
但不知道这个位置怎么写.