1
如果我用這個代碼,而原型框架:爲什麼array.prototype.map.call(..)在使用那裏的原型框架的情況下不起作用?
if (XMLHttpRequest.prototype.sendAsBinary) return;
XMLHttpRequest.prototype.sendAsBinary = function(datastr) {
function byteValue(x) {
return x.charCodeAt(0) & 0xff;
}
console.log(Array.prototype.map);
var ords = Array.prototype.map.call(datastr, byteValue);
var ui8a = new Uint8Array(ords);
this.send(ui8a.buffer);
}
數收益:
function map() { [native code] }
如果原型JS框架中包括然後登錄返回此一個:
function collect(iterator, context) {
iterator = iterator || Prototype.K;
var results = [];
this.each(function(value, index) {
results.push(iterator.call(context, value, index));
});
return results;
}
同時我遇到了一個錯誤:
Uncaught TypeError: Object [object String] has no method 'each' prototype.js:864
collect prototype.js:864
XMLHttpRequest.sendAsBinary jquery.filedrop.js:309
send jquery.filedrop.js:215
無論如何,jQuery也在使用。
jQuery.noConflict();
爲什麼我不能在原型框架打開的情況下運行本地映射函數?
是'datastr'數組? (答案是否定)原型用自己的方法覆蓋'Array.prototype.map'。該方法似乎不適用於字符串。 –
我想你可以通過將字符串設置爲一個數組''datastr.split(「」)'來修復它,在這一點上,你可以簡單地做'var ords = datastr.split(「」)。map(byteValue) –
datastr是一個圖像字符串數據。 – Anthony