top | item 3815644

(no title)

russfrank | 14 years ago

That's because "override the 'general' toString() function" doesn't make sense. This is a method. It must be overriden for a particular class of objects.

The first part of your example is due to the conversion between primitives and objects for method calls. It has little to do with prototypal inheritance.

Then, you override the method on an instance of String. When you set toString to null, of course, the call to toString fails.

Lastly, you override it on the prototype of String, which will apply to all String objects. Why is this an unexpected error? toString is on the prototype, because it's defined on the class, not the instance. I'm not sure what the confusion is here.

discuss

order

No comments yet.