I don't know if you saw this: in addNotification there is already a replace mechanism, see https://github.com/mozilla-b2g/gaia/blob/master/apps/system/js/notifications.js#L316-L323

I'm sure you can use this instead of adding this function?