07-24-2023, 08:55 AM
I'm trying to figure out if there is a way to have an object property defined in its prototype as a dynamic value that can change every time an instance of the object is created. That's kind of the best way I can describe it; I have made a fiddle to show what I'm trying to do (though it doesn't work).
var Response = {
LCID: 321
};
Date.prototype.LCID = Number(0);
Date.prototype.LCID.valueOf = function() { return Response.LCID; };
document.write((new Date()).LCID);
Response.LCID = 456;
document.write((new Date()).LCID);
What I'm trying to achieve is that `Response.LCID` can change over the lifetime of the code as you can see from me changing its value in the code later on. Whenever I create a `Date` object, I want the value of `(new Date()).LCID` to be the current value of `Response.LCID`, not just the value that it had when I first create `Date.prototype.LCID`.
Is there any way this can be done? The biggest limitation is that it has to work in JavaScript 1.5... though I would be curious to see if it could be done in recent versions.
var Response = {
LCID: 321
};
Date.prototype.LCID = Number(0);
Date.prototype.LCID.valueOf = function() { return Response.LCID; };
document.write((new Date()).LCID);
Response.LCID = 456;
document.write((new Date()).LCID);
[To see links please register here]
What I'm trying to achieve is that `Response.LCID` can change over the lifetime of the code as you can see from me changing its value in the code later on. Whenever I create a `Date` object, I want the value of `(new Date()).LCID` to be the current value of `Response.LCID`, not just the value that it had when I first create `Date.prototype.LCID`.
Is there any way this can be done? The biggest limitation is that it has to work in JavaScript 1.5... though I would be curious to see if it could be done in recent versions.