Skip to content

Commit

Permalink
capricorn86#728@patch: Use proxy for attributes getter.
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasbach committed Apr 25, 2023
1 parent 1a827e3 commit f17155f
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion packages/happy-dom/src/nodes/element/Element.ts
Expand Up @@ -255,7 +255,23 @@ export default class Element extends Node implements IElement {
* @returns Attributes.
*/
public get attributes(): INamedNodeMap {
return Object.assign(new NamedNodeMap(this), Object.values(this._attributes), this._attributes);
return new Proxy(new NamedNodeMap(this), {
get: (target, name) => {
if (name in target && typeof target[name] === 'function') {
return (...args) => target[name](...args);
}

if (typeof name === 'symbol') {
return target[name];
}

if (typeof name === 'string' && /^\d+$/.test(name)) {
return Object.values(this._attributes)[parseInt(name, 10)];
}

return this._attributes[name] || target[name];
}
});
}

/**
Expand Down

0 comments on commit f17155f

Please sign in to comment.