Better way to delay a function for a few seconds? Javascript

It is more of an "inconvenience" than a problem.

I often find myself creating a bunch of booleans in order to stop something from happening more than ones.

Exsample

private var ReadyToFire : boolean = true;

function Update() {

   if(pulltrigger && ReadyToFire)
   {
       ReadyToFire = false;
       fire();
       resetReadyToFire();
   }
}

function resetReadyToFire(){
yield WaitForSeconds(2);
ReadyToFire = true;
}

Every time I do this, I feel like there has to be a simpler way to achieve what I am after. I always end up with a ton of functions and boolean variables just because I need to delay something.

Don't use Update...it runs every frame, so to make stuff not happen every frame, you need a bunch of hacks, as you discovered. Just stick to coroutines instead.

function Start () {
   while (true) {
      while (!pullTrigger) yield;
      Fire();
      yield WaitForSeconds(2.0);
   }
}