Skip to content

Instantly share code, notes, and snippets.

@wycats
Created March 28, 2013 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wycats/89b2a49a3431b04e88c7 to your computer and use it in GitHub Desktop.
Save wycats/89b2a49a3431b04e88c7 to your computer and use it in GitHub Desktop.
// 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