1
我試圖構建一個包含canvas上下文對象的屬性值的字符串。我使用的是我測試過的所有瀏覽器的代碼,除了IE瀏覽器10.下面的代碼:查詢對象屬性適用於除IE之外的所有瀏覽器10
getCanvasInfo : function (canvas) {
var props = [],
prop,
ctx = canvas.getContext('2d');
for (prop in ctx) {
if (ctx.hasOwnProperty(prop) &&
prop !== "canvas" &&
typeof ctx[prop] !== "function")
{
props.push(prop);
}
}
return props.sort().map(function (p) {
return p + ": " + ctx[p];
}).join("\n");
}
在IE 10(移動和桌面),該if
測試似乎排除所有屬性,當循環退出時,將props
留爲空數組。我在調試器中驗證了ctx
確實在輸入for..in
循環時具有預期的(非功能)屬性。這是怎麼回事?