Understanding valueOf function with Inheritance