• (forum is messing with us again... so I try again:)

    ...but with an a logical error, as I point out in #8. Because the original code - writing modules using new feature class - interestingly *** also from @MaBe *** - does not start the stopwatch on creation... just as I suggested.

    There is nothing wrong to add the auto, because you do not want to have the extra code of starting the stopwatch. That's why you / @MaBe allow the "auto" to be passed. Makes absolute sense to me. To make the stopwatch robust though, it should object to start a started stopwatch with Illegal State Exception, which means that at the state the object is right now, a start is not possible... An additional property can indicate that the stopwatch is started or stopped. Combination of particular values of startTime and endTime could do that too: both are 0 or both are not 0 can do the test. Therefore:

         ...
        // Method start()
          start() { 
            if (    (this.timeStart === 0 && this.timeStop === 0)
                 || (this.timeStart !== 0 && this.timeStop !== 0)
               ) {
               this.timeStart = Date.now();
               this.timeStop = 0;
             } else {
                throw "Illegal State Exception - stop watch already already started / is running."
             }
          }
          ...
    

    See try...catch and throw in MDN...:

    1. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/try...catch
    2. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/throw

    Regarding your proof: works as designed / as by your setup. There is nothing that needs to be proofed. It is how the system works and nothing is found at fault with it.

About

Avatar for allObjects @allObjects started