Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Re: Does anyone want to take a stab at this?

5 views
Skip to first unread message

Mark Filipak

unread,
Oct 6, 2009, 6:10:05 PM10/6/09
to jeffry killen, dev-web-d...@lists.mozilla.org
I don't really know what you intend, but try String() for conversions.

for(i = 0; i < size; i++) // group coordinate values as pairs to make cell origin coords
{
this.tiles[i] = new Array();
for(j = 0; j < size; j++)
{
this.tiles[j] = new Array();
this.tiles[j][0] = this.posLeft[j] + this.originLeft; // <<= x placement
this.tiles[i][1] = this.posTop[i] + this.originTop; // <<= y placement
apush(this.pairs, String(this.posTop[i] + this.originTop)+":"+String(this.posLeft[j] + this.originLeft));
}
}


jeffry killen wrote:
> I am working on a javascript object that produces an array of
> coordinates representing
> a square grid.
>
> I have test this in non object code and it works.
> But the following code produces bad results:
> Object constructor function code........
> for(i = 0; i < size; i++) // group coordinate values as pairs to make
> cell origin coords
> {
> this.tiles[i] = new Array();
> for(j = 0; j < size; j++)
> {
> this.tiles[j] = new Array();
> this.tiles[j][0] = this.posLeft[j] + this.originLeft;
> // <<= x placement
> this.tiles[i][1] = this.posTop[i] + this.originTop; //
> <<= y placement
> //tmp = this.tiles[i][1]+":"+this.tiles[j][0]; -> "NaN"
> // alernative syntax produces the same result
> //tmp =
> Math.toString(this.tiles[i][1])+":"+Math.toString(this.tiles[j][0]); ->
> "[object:Math]:[Object:Math]"
> tmp = Math.toString(this.posTop[i] +
> this.originTop)+":"+Math.toString(this.posLeft[j] + this.originLeft);
> // each pair has to be immediately exported
> apush(this.pairs, tmp); // final list to export: apush()
> in another sourced js file
> }
> }
>
> What is happening here; that does not happen in the non object code, is
> when the multi dimensional array items are concatinated with ':', a math
> operation is taking place and the result stored in this.pairs is NaN.
> So, I am trying to coerce the data type to a string representation but
> what I
> get is "[object:Math]:[Object:Math]" instead:
> not what I want; (for instance):
> "10:10"
> "10:25"
> "10:40"
> "25:10"
> "25:25"
> "25:40"
> "40:10"
> "40:25"
> "40:40"
>
> Can anyone suggest a fix?
> Platform: Mac OSX 10.5x, Firefox 3.5.2
> Thank you in advance
> JK
>
> ps: I have written a php non OO version that also works.
>
> _______________________________________________
> dev-web-development mailing list
> dev-web-d...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-web-development
>

0 new messages