Another approach for Bob example in javascript