Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Function construction, multiple arguments

I've got a couple of blocks in the index.js for the watch face I've been playing with that operate on the onclick event of a hidden <rect> to toggle the visibility of elements. It's not the tidiest way of doing it, but it was the only way I could get it working. Anyway, is there an easy way of tidying up this code block to run it as a function so I can call it from a util.toggler(arg1, arg2) - where arg1 and arg2 are the "ArcFrame" parts in the current code - type arrangement? (Very) Basic javascripting I can muddle through but function construction I'm still just at the starting blocks.

 

if (stepArcFrame.style.display == "inline" && calArcFrame.style.display == "none") {
        stepArcFrame.style.display = "none";
        calArcFrame.style.display = "inline";
     }
      else
       {
         stepArcFrame.style.display = "inline";
         calArcFrame.style.display = "none";
       }
     } 

 

Best Answer
0 Votes
1 REPLY 1

Something like this?

 

// util.js Toggle Show/Hide
export function toggler(ele) {
  ele.style.display = (ele.style.display === "inline") ? "none" : "inline";
}

// index.js
import * as util from "util";

util.toggler(stepArcFrame);
util.toggler(calArcFrame);
Best Answer
0 Votes