-
-
Save wycats/89b2a49a3431b04e88c7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// web/branding.js | |
export let hasBrand = new Symbol(); | |
// web/html_element.js | |
import { hasBrand } from "web/branding"; | |
import { create } from "js/mop" | |
let brandedObjects = new WeakSet(); | |
export class HTMLElement extends Element { | |
} | |
Object.defineProperty(HTMLElement, create, { | |
value: function(...args) { | |
let obj = super(...args); | |
brandedObjects.add(obj); | |
}, | |
writable: false, | |
configurable: false | |
}); | |
Object.defineProperty(HTMLElement, hasBrand, { | |
value: function(object) { | |
return brandedObjects.has(object); | |
}, | |
writable: false, | |
configurable: false | |
}); | |
// somewhere else... | |
import { HTMLElement } from "web/html_element"; | |
import { hasBrand } from "web/branding"; | |
var el = new HTMLElement('div'); | |
HTMLElement[hasBrand](el); // true | |
HTMLElement[hasBrand]({}); // false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment