あなたはこれがユニークである必要がある宇宙を説明しません。
絶対に一意であることを意味する場合は、UUIDについて話していることになります。
クライアント側のキャッシュを防ぐためにエンドポイントに固有の何かが必要な場合は、これで十分です。
var unique = new Date().getTime();
これら2つ以外のものが必要な場合は、より具体的にする必要があります。
編集
多分このように見えるもの
jsonRpcClient = function()
{
var requestStack = [null];
this.makeRequest = function()
{
var id = this.getAvailableSlot();
requestStack[id] = new this.request( id, arguments );
}
this.getAvailableSlot: function ()
{
for ( var i = 0; i < requestStack.length: i++ )
{
if ( null == this.requestStack[i] )
{
return i;
}
}
return i;
}
this.request: function( id, args )
{
// request stuff here
// pass id and whatever else to jsonRpcClient.handleResponse()
}
this.handleResponse: function( id )
{
var request = requestStack[id];
requestStack[id] = null;
// Do whatever with request
}
};