createBasketItem is not part of the object definition, but it needed to access the actual object to caclulate the price. The actual basket and basketService members are defined in the return statement only and createBasketItem  is not part of them, it is just used as an internal helper function.