J
javadesigner
A proposal to standarize (by convention) giving javascript objects a
unique 'id'. This is useful when doing object comparisons etc. (one
can use === but this prints out better when debugging, I think)
------------------------- set id -----------------------------
function setid(o) {
if (o.id)
return o;
if (! window._idcount)
window._idcount = 1;
o.id = "id: " + window._idcount++ + '/' +
Object.prototype.toString.call(o);
return o;
};
-----------------------------------------------------------------
Example Usage:
function foo() {
setid(foo.prototype);
};
var f1 = new foo();
setid(f1);
alert(foo.prototype.id)
alert(f1.id)
Comments and thoughts ?
Best regards,
--j
unique 'id'. This is useful when doing object comparisons etc. (one
can use === but this prints out better when debugging, I think)
------------------------- set id -----------------------------
function setid(o) {
if (o.id)
return o;
if (! window._idcount)
window._idcount = 1;
o.id = "id: " + window._idcount++ + '/' +
Object.prototype.toString.call(o);
return o;
};
-----------------------------------------------------------------
Example Usage:
function foo() {
setid(foo.prototype);
};
var f1 = new foo();
setid(f1);
alert(foo.prototype.id)
alert(f1.id)
Comments and thoughts ?
Best regards,
--j