-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Labels
bugSomething isn't workingSomething isn't working
Description
由于对Object创建了自定义方法,
for ( .. in ..)
for (.. of .. )
这两种循环总是会遍历到第一个自定义方法
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; | |
| } |
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working