JavaScript implementation.