I use a plain JavaScript object to wrap the Pushpin and its functionality, so that instead of storing custom properties on the Pushpin, I store them on the wrapper object.
For example, assuming we have a map and location specified, we can then create our object:
var Pin = function(location, map) {
this._pushpin = new Microsoft.Maps.Pushpin(location);
map.entities.push(this._pushpin);
this.id = (new Date).valueOf();
var self = this;
Microsoft.Maps.Events.addHandler(this._pushpin, 'click', function() {
console.log(self.id);
})
};
This way, when we need to reference the id of the pushpin later, e.g. when the pushpin is clicked, then we can fetch the id of the wrapper object.
It's a good practice to use the public API for extending the Bing Maps objects.
Wrote a blog post about it here.