How to track a string-variable in JavaScript -
requirement : able track string variables in javascript assigning unique id each variable.
example:
var = 'alkd'; var b = 'iquwq'; console.log(a.id); # 1234 console.log(b.id); # 5678
what have tried : have tried extending string object adding new method or property 'string.prototype'
output :
console.log(a.id); #1234 console.log(b.id); #1234 (returning same id above)
what have observed : ever instance of string inherited string.prototype. changes string.prototype object propagated string instances.
example :
a.id = 8783; # setter console.log(b.id)# returns 8783
my questions :
- is possible required functionality extending string object?
- is there alternative way this?
- are there plans add functionality future editions of ecmascript?
maybe don't understand trying do, if want assign id variable , have value variable along getters , setters, can use json object
// initialize var = {id: 0, value: "zero"}; // console.log(a.id); console.log(a.value); // set a.id = 1; a.value = "one"; // console.log(a.id); console.log(a.value);
Comments
Post a Comment