Jump to content

Recommended Posts

Posted

I've spent alot of time writing javascript lately, mainly handling events. (I know this is a CAD board but the principal is the same)

 

What I've realised is that i end up writing conditional statements with the same conditional statements for either result of the first

 

 

for example:

 

if( A == true){
 if(c==d){
     action(A+d)
 }
 else{
   action(A+c)
 }
}
else{
  if(c==d){
     action(A+d+1)
 }
 else{
   action(A+c+1)
 }
}

 

This is a relatively small example. My main reasoning is not creating unecessary local variable since js doesn't have manual garbage collection

 

What are the communities thoughts on the matter?

 

Ollie

Posted

Perhaps use an 'if-else' structure?

 

if ((c == d) && (A == true))
 action(A+d)
 else if (c == d)
 action(A+d+1)
 else if (A == true)
 action(A+c)
 else
 action(A+c+1)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...