garywill/cc-visualize

对array或object使用for in 或for of循环时,会撞到自定义的方法

Opened this issue · 0 comments

由于对Object创建了自定义方法,
for ( .. in ..)
for (.. of .. )
这两种循环总是会遍历到第一个自定义方法

cc-visualize/common.js

Lines 13 to 61 in 83f435f

Object.prototype.q$ = function(selectorStr) {
function handleNonArrayObject(obj)
{
return obj.querySelector(selectorStr);
}
var obj = this;
var result = null;
if ( HTMLElement.prototype.isPrototypeOf(obj) )
result = handleNonArrayObject( obj );
else if ( typeof(obj) != "string" &&
obj.length !== undefined && obj.length > 0
)
{
for( subObj of obj )
{
result = handleNonArrayObject(subObj);
if (result)
break;
}
}
return result;
}
Object.prototype.q$$ = function(selectorStr) {
function handleNonArrayObject(obj)
{
return obj.querySelectorAll(selectorStr);
}
var obj = this;
var result = [];
if ( HTMLElement.prototype.isPrototypeOf(obj) )
result = Array.from( handleNonArrayObject( obj ) );
else if ( typeof(obj) != "string" &&
obj.length !== undefined && obj.length > 0
)
{
for( subObj of obj )
{
result = result.concat ( Array.from (handleNonArrayObject(subObj) ) );
}
result = Array.from ( new Set(result) );
}
return result;
}