有人能告訴我爲什麼我在我的js中獲得successCallback is not a function
嗎?successCallback不是函數
這是調用它的代碼:
function fillData(data){
this.raw = data;
}
function AnimatedModel(posx, posy, posz,sx,sy,sz,r,g,b,a, name, yd){
this.x = posx;
this.y = posy;
this.z = posz;
this.scale = new Array(sx,sy,sz);
parseBinFile(this, name)
this.r = r;
this.g = g;
this.b = b;
this.a = a;
this.yawDeg = yd;
this.fillData = fillData;
}
var zombie = new AnimatedModel(0,0, 0, 0.2,0.2,0.2, 0.0,1.0,0.6,0.2, "zom3.ms3d", 0);
function parseBinFile(model, name){
getServerFileToArrayBufffer(name, model.fillData)
console.log(model.raw);
}
function getServerFileToArrayBufffer(url, successCallback){
// Create an XHR object
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (xhr.readyState == xhr.DONE) {
if (xhr.status == 200 && xhr.response) {
// The 'response' property returns an ArrayBuffer
successCallback(xhr.response);
} else {
alert("Failed to download:" + xhr.status + " " + xhr.statusText);
}
}
}
// Open the request for the provided url
xhr.open("GET", url, true);
// Set the responseType to 'arraybuffer' for ArrayBuffer response
xhr.responseType = "arraybuffer";
xhr.send();
}
編輯:忘了fillData功能。
那麼「fillData」值從哪裏來?這就是你作爲「successCallback」傳遞的信息。看來,這不是一個功能。 – Pointy
我只是忘了它。與以前一樣的錯誤。 – CyanPrime
'successCallback'不是一個函數。 (在'getSever..'這一點被稱爲'model.fillData'的計算結果是* undefined *,因爲直到調用*'parseBinFile'之後纔會設置該屬性,所以'successCallback'是* undefined *:JavaScript是*嚴格評估*。) – 2012-06-28 23:01:55