get-id
Keep track of your JS objects (and functions) via a unique id.
Install:
npm install --save get-id
Usage:
// or:// var getid = require('get-id'); var object = {} object2 = {}; var objid = ;var obj2id = ; objid === ;obj2id === ;
What's happening?
getid
assigns an id (int) to a non-enumerable, non-writable property on the
passed object or function under the key __object_id__
, and then returns it.
Using a custom id property name
If for whatever reason you don't want to use the __object_id__
key, you can
generate a custom getid
function using the exported create
function:
; const customgetid = ;const object = {};const objectid = ; objectid === object'__this_is_a_custom_key';