[DOC] Tricks Javascript, maybe toint not needed?

Game development with Board Game Arena Studio
Post Reply
User avatar
Rudolf
Posts: 566
Joined: 24 December 2011, 23:04

[DOC] Tricks Javascript, maybe toint not needed?

Post by Rudolf »

Hello;
I saw in BGA doc, the javascript trick 'toint(i) to avoid against 'string' compiler undrestanding...
I would like to add this trick (i think it's less complicate) :)

Code: Select all

var i=1, j=1;
	alert ("1+1="+i+j);  /* displays 11 */
	alert ("1+1="+(i+j)); /* displays 2 */ 
no need to use toint()?
User avatar
sourisdudesert
Administrateur
Posts: 4630
Joined: 23 January 2010, 22:02

Re: [DOC] Tricks Javascript, maybe toint not needed?

Post by sourisdudesert »

Hello,

Of course you can use this method too. The idea of "toint" is to make it explicit so you can't have some doubts. There are also situation (ex: comparisons) where the parenthesis method does not work.

Cheers,
Post Reply

Return to “Developers”