javascript - Addition and subtraction within bounds -


how write following in javascript:

    row-=21;     if (row < 1) {         row = 1;     } 

you can this:

row = math.max( row-21, 1); 

edit:

if want able set minimum and/or maximum range, prototype own function number.

number.prototype.adjust = function( adj, min, max ) {     if( isnan( min ) ) min = -infinity;     if( isnan( max ) ) max = infinity;     var res = + ~~adj;     return res < min ? min : res > max ? max : res; }; 

then can use this:

row = row.adjust( -21, 1, 50 ); /* adjustment, min, max */ 
  • 1st argument adjustment
  • 2nd argument minimum range (pass null no min)
  • 3rd argument maximum range (pass null or leave blank no max)

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -