Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement build-in id() function (example included) #723

Open
faerot opened this issue Apr 20, 2020 · 0 comments
Open

implement build-in id() function (example included) #723

faerot opened this issue Apr 20, 2020 · 0 comments

Comments

@faerot
Copy link

faerot commented Apr 20, 2020

Python function id() is very useful and it is trivial to implement using WeakMap, all you need to is is adding to __builtin__.js this code:

var _id_registry = new WeakMap();
var _id_counter = 0;

export function id(obj) {
    var id = _id_registry.get(obj);
    if (id === undefined) {
        id = ++_id_counter;
        _id_registry.set(obj, id);
    }
    return id;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants