0

Fiddle here: http://jsfiddle.net/rhodee/4NKVH/

I've been reading the Crockford book and was wondering what is a proven approach to prying open the base constructor object and adding a function to it that child objects can access?

I thought I could access the prototype of my object and it appears that is not possible given my current code.

Thanks for any ideas.

1 Answer 1

1

You have several errors:

  • Your constructor function returns a totally unrelated object. Don't do that. Return this. (If no return statement exists, the constructor does this implicitly)
  • Superconstructor calls are not very intuitive in JS. You need the ugly construct MySuperclass.call(this, arg1, arg2, ...);, so in your case mammal.call(this, spec); in the cat class
  • You need the new keyword to instantiate an object that uses the prototype chain.

See http://jsfiddle.net/4NKVH/5/ for a fixed version of your code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.