# HG changeset patch # User Emmanuel Gil Peyrot # Date 1327721305 -3600 # Node ID 88d24231bf248ef55a64ffe384f1ae28e65f7df5 # Parent 8b739d4e094b2d2c767b3cc0161cdd0b41ffd361 Better newId function. diff --git a/lightstring.js b/lightstring.js --- a/lightstring.js +++ b/lightstring.js @@ -68,7 +68,20 @@ var Lightstring = { */ dom2xml: function(aElement) { return this.serializer.serializeToString(aElement); - } + }, + /** + * @function Get an unique identifier. + * @param {String} [aString] Prefix to put before the identifier. + * @return {String} Identifier. + */ + newId: (function() { + var id = 1024; + return function(prefix) { + if (typeof prefix === 'string') + return prefix + id++; + return '' + id++; + }; + })(); }; /** @@ -80,11 +93,6 @@ Lightstring.Connection = function(aServi if (aService) this.service = aService; this.handlers = {}; - this.iqid = 1024; - this.getNewId = function() { - this.iqid++; - return 'sendiq:' + this.iqid; - }; this.on('stream:features', function(stanza, that) { var nodes = stanza.querySelectorAll('mechanism'); //SASL/Auth features @@ -300,7 +308,7 @@ Lightstring.Connection.prototype = { if (elm.tagName === 'iq') { var id = elm.getAttribute('id'); if (!id) { - elm.setAttribute('id', this.getNewId()); + elm.setAttribute('id', Lightstring.newId('sendiq:')); str = Lightstring.dom2xml(elm); } if (aCallback)