Wow, this is a lot of questions. Let it work through them.
Is this just a link to another object? Or is it a link to a pointer to another object?
JavaScript has no pointers. However, a variable or property containing an βobjectβ actually contains a reference to the object, so other variables may contain references to the same object.
Global.prototype = ??
The global object ( window , if you want), where all global variables are defined, does not have a prototype (do not care about exceptions in some environments).
I still can't figure out what the .prototype property is in Javascript.
The .prototype property is a property that all function objects have, pointing to their prototype object (a simple object).
You should not confuse it with the prototype internal link that every object has. This prototype points to an object that looks at properties that the object does not have.
Function.prototype = ??
This is the object from which all Function objects are inherited. It contains things like call or bind .
var obj1 = {}; // obj1.prototype = Object var func1 = function() {}; // func1.prototype = Function
Yes, kinda. I think you have a concept, but I do not know the terminology. While func.prototype is different, the obj.prototype property does not even exist. However, you meant internal prototypes - we can access them through the Object.getPrototypeOf function. And they do not relate to constructor functions, but relate to their prototype objects. Here's the fix:
Object.getPrototypeOf(obj1) === Object.prototype Object.getPrototypeOf(func1) === Function.prototype
should it be "new foo" or "new foo ()"?
It does not matter, they are equivalent. You only need parentheses when you want to pass arguments.
var Foo = function() { this.prop1 = 0; } var foo = new Foo();
Again, your assumptions were correct, but were expressed incorrectly. Let me work with the details.
Above, I talked about "prototype objects." What is it? These are simple objects that are implicitly created with each function. In this case, it is Foo.prototype - an empty object. So, we are dealing with three objects: the Foo constructor, its prototype Foo.prototype and an instance of Foo .
What is special about Foo ? This is the first thing the new operator does. When a function is called as a constructor - using new - then its .prototype property is .prototype and a new object is created with its internal prototype set for this prototype object. This is a miracle. After that, the function is called in a new instance, so this is a new object; and in your case, it creates the .prop1 property on the instance. Then the result is returned (and assigned to Foo ).
How to use this magic now? The point is to create the properties of a prototype object, which will then be inherited.
// modify `Foo.prototype`, the object which `foo` inherits from: Foo.prototype.prop2 = 1; console.log(foo.prop2); // 1!
I also don't understand how to change prototypes around.
The problem is that this is completely impossible. After creating the instance, the prototype chain of the object is pretty static. However, you do not need this often.
goo.prototype = new Foo();
This did not work because the .prototype property .prototype not what you expected.
var c = new C(); C.prototype = new A();
It only works a little. See above what new does - it searches for the constructor's .prototype property only once. The internal prototype remains locked - you do not change the instance c . However, if you now create a new instance of var d = new C() , it will inherit instance A
I hope this helps; If you have additional questions, please comment.