* return the child corresponding to the given property and value. * note : avoid calling this function every frame since * it parses the whole object tree each time * @param {string} prop - Property name * @param {string|RegExp|number|boolean} value - Value of the property * @returns {
(prop, value, objList = [])
| 617 | * let inViewport = container.getChildByProp("inViewport", true); |
| 618 | */ |
| 619 | getChildByProp(prop, value, objList = []) { |
| 620 | this.forEach((child) => { |
| 621 | const v = child[prop]; |
| 622 | if (value instanceof RegExp && typeof v === "string") { |
| 623 | if (value.test(v)) { |
| 624 | objList.push(child); |
| 625 | } |
| 626 | } else if (v === value) { |
| 627 | objList.push(child); |
| 628 | } |
| 629 | if (child instanceof Container) { |
| 630 | child.getChildByProp(prop, value, objList); |
| 631 | } |
| 632 | }); |
| 633 | |
| 634 | return objList; |
| 635 | } |
| 636 | |
| 637 | /** |
| 638 | * returns the list of children with the specified class type |
no test coverage detected