Skip to content

Comment on Andro.jsparent

Comments

Strings can work fine for event names, I think op is overstating the string hell factor. But say you wanted to eliminate them you could do something like:

  var firstTouchBehaviour = {
    touchCount: 0,
    events: {
      firstTouch: 'FirstTouch'
    }, 
    setup: function(owner) {
      andro.eventer(owner).bind(this, "touch", function(contact) {
        if(contact === "added") {
          if(this.touchCount === 0) {
            andro.eventer(owner).emit(this.events.firstTouch);
          }
          this.touchCount++;
        } else if(contact === "removed") {
          this.touchCount--;
        }
      });
    }
  };
and
  var soundBehaviour = {
    setup: function(owner) {
      andro.eventer(owner).bind(this, firstTouchBehaviour.events.firstTouch , function() {
        console.log("Rarrrrrwwwwwwwwwwwwwwww");
      });
    }
  };

Yes, I agree.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.