javascript timer abstraction