Is there a possible way via JavaScript to access a DOM Element via its constructor (preferably HTMLElement
) through a custom property or just directly?
Something like the code below:
/* Some Attribute
document.body.someAttribute == document.body
(this should be true)
*/
HTMLElement.prototype.someAttribute = (function() {
/* Return the element. */
})();
EDIT
Apparently this was what I was asking:
Object.defineProperty(HTMLElement.prototype, "someAttribute", {
get: function someAttribute() { return this }
});
document.body.someAttribute === document.body // -> true