Skip to content

Instantly share code, notes, and snippets.

@senyai
Created April 29, 2024 15:07
Show Gist options
  • Save senyai/cec45d4e4886f86cefa283d24486ba5f to your computer and use it in GitHub Desktop.
Save senyai/cec45d4e4886f86cefa283d24486ba5f to your computer and use it in GitHub Desktop.
// based on https://stackoverflow.com/questions/1997661/unique-object-identifier-in-javascript
const getID = (function() { // FOR DEBUG ONLY. DO NOT COMMIT!
var id = 0;
return function(o: any): number {
if ( typeof o.__uniqueid != "undefined" ) {
return o.__uniqueid;
}
Object.defineProperty(o, "__uniqueid", {
value: ++id,
enumerable: false,
// This could go either way, depending on your
// interpretation of what an "id" is
writable: false
});
return o.__uniqueid;
};
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment