javascript literal initialisation loop
Posted
by graham.reeds
on Stack Overflow
See other posts from Stack Overflow
or by graham.reeds
Published on 2010-04-16T05:06:50Z
Indexed on
2010/04/16
5:13 UTC
Read the original article
Hit count: 324
JavaScript
|literal
I have an object which has several properties that are set when the object is created.
This object recently changed to object literal notation, but I've hit a bit of a problem that searching on the net doesn't reveal.
Simply stated I need to do this:
Star = function(_id, _x, _y, _n, _o, _im, _c, _b, _links) {
var self = {
id: _id,
// other properties
links: [],
for (var i=0,j=0;i<8;i++) { //<- doesn't like this line
var k = parseInt(_links[i]);
if (k > 0) {
this.links[j++] = k;
}
},
// other methods
};
return self;
};
How do I initialise a property in the constructor in object literal notation?
© Stack Overflow or respective owner