Re: Very strange problem with Class object
- From: VK <schools_ring@xxxxxxxxx>
- Date: Sun, 30 Mar 2008 15:39:47 -0700 (PDT)
On Mar 31, 2:22 am, Piotr K <piotr.korzeniew...@xxxxxxxxx> wrote:
I simply ran out of ideas why this piece of code works so strange,
it's a very simple class creating object:
var Class = function(tpl) {
return function() {
for(var t in tpl) this[t] = tpl[t];
};
}
var X = new Class({
arr: []
});
var x = new X;
x.arr.push(5);
var y = new X;
alert(y.arr[0]) // displays 5
How, I mean HOW in the world it displays 5? I tested it with normal
string and number variables - works fine, but I can't figure what's
wrong with the arrays? I tried to change the Class function in many
ways like making "new Object(tpl[t])" or "tpl[t].valueOf()" but
nothing helped.. I'm frustrated, it's so freakin strange..
Because you have created a very efficient memory leak over closure
with tpl value retained in it. I honestly have no idea what does this
code suppose to mean. Is it some work-on-denial test for a script
engine? There are more sophisticated professional packages for that,
Acid 3 from the first coming into my mind.
.
- Follow-Ups:
- Re: Very strange problem with Class object
- From: Piotr K
- Re: Very strange problem with Class object
- References:
- Very strange problem with Class object
- From: Piotr K
- Very strange problem with Class object
- Prev by Date: Strange problems with JSON and Safari
- Next by Date: Re: Very strange problem with Class object
- Previous by thread: Very strange problem with Class object
- Next by thread: Re: Very strange problem with Class object
- Index(es):
Relevant Pages
|