I noticed that I’ve been using both in my code – interchangeably and randomly. Particularly, when I have a call back and I need a value to persist when the function is “called back”. Does it matter whether you use passed parameters or static parameters? By static I mean function object properties. I’m using the term loosely. Here is the example I’m working on.
message_object.display( type );
document.getElementById( 'po_but_cov' ).style.display='inline';
pos = 30;
MC.MATweet.movePane.dir = 'down';
MC.MATweet.movePane( pane_element, pos );
return o_p;
},
movePane: function( pane_element, pos ) {
if( ( MC.MATweet.movePane.dir === 'down' ) && ( pos < 70 ) ) {
pos += 1;
pane_element.style.top = ( pos ) + 'px';
setTimeout( function( ){ MC.MATweet.movePane( pane_element, pos ); }, 1 );
}
else if( ( MC.MATweet.movePane.dir === 'down' ) && pos === 70 ) {
MC.MATweet.movePane.dir = 'up';
setTimeout( function( ){ MC.MATweet.movePane( pane_element, pos ); }, 2000 );
}
else if( ( MC.MATweet.movePane.dir === 'up' ) && ( pos > 30 ) ) {
pos -= 1;
pane_element.style.top = ( pos ) + 'px';
setTimeout( function( ){ MC.MATweet.movePane( pane_element, pos ); }, 1 );
}
else if( ( MC.MATweet.movePane.dir === 'up' ) && ( pos === 30 ) ) {
document.getElementById( 'po_but_cov' ).style.display='none';
}
},
As you can see I use pos as a passed parameter and I use MC.MATweet.movePane.dir as a static parameter. I need both available when the function is called back after set amount of time.
I’d like to make the style of my code more consistent. For some reason, the value that changes more, pos, I passed as a parameter, and the value that changes only once MC.MATweet.movePane.dir I used as a static variable. Don’t think this is relevant, just reflecting.
How can I be more consistent? Does it matter which one you choose?
FYI, this code just animates a box, moving it down, pausing, and moving it back up.
Went ahead with straight parameters for now so I could move initialization into the initial function call.
Resulting code: