hash map – Javascript object to be used as a key in a Map


I have a use-case where we need to use a javascript object as a key in a Map. If we don’t implement a toString() method we’re going to end up with (object Object) by default so i came up with the below pattern. Are there any drawbacks to this, or a better way to achieve this?

var Name = function(name) {
    this.name = name;
    this.id = Math.random().toString(36).slice(2);
}

Name.prototype.toString = function() {
    return this.id;
}