Say I have a function.

function foo(){
    //do stuff

And then I create an object of that function.

var fooObj = new foo();

What is fooObj called? An instance, An object instance, or something else entirely? Pardon the newbie question, but I am rather new to prototype based programming(and all programming really).


fooObj is an object and it is also an instance of the foo prototype.

Though javascript doesn't technically have classes, many would also call fooObj an object of the foo class because it works somewhat similarly to classes in other languages.

  • This is not correct. prototype is a property of a constructor. fooObj is an instance of the foo constructor, not the foo constructor's prototype which is itself is an object or instance of something else. – Erik Reppen Feb 13 '13 at 13:04
  • I didn't say it was an instance of the foo constructor's prototype. I said it was an instance of the prototype. The prototype is the template for the object and using new makes an object from the prototype and calls the constructor. – jfriend00 Feb 13 '13 at 14:59
  • Sorry. I meant "not an instance of the foo constructor's prototype." Should have been more clear. It can be thought of the way you describe but really prototype is just a backup object that gets referred to when you try to call a method that's not directly attached to the instance. It works like a backup object but serves as an inheritance mechanism. constructors create instances and they have prototypes. Instances have constructors with prototypes they inherit from. It matters when explaining why prototype methods can't access internal vars that this.<method> properties can. – Erik Reppen Feb 13 '13 at 15:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.