This question has already been answered:
- Prototype Inheritance 2 Responses
Please explain why the function call occurs?
Foo = function() { document.write("Hello"); } var Bar = function() { Foo.call(this); } Bar.prototype = new Foo();
Do I understand this code correctly?
I reason like this:
1) The normal foo()
function simply prints "Hello"
2) In the body of the Bar()
function, Foo()
is called in the context of the Bar.prototype
object? I make a similar conclusion, since this
in the case of calling the function Foo()
with new
should point to the object that is the left operand of the assignment operation (clumsy, but this is from observations and hardware)!
3) Well, the last thing that is not clear to me. Bar.prototype
is the same object reference that will be the prototype for objects created using the Bar()
function? That is, we assign to the Bar.prototype
object a new
object constructed with the help of new
, in whose body the only document.write()
instruction, in general, for the first time, I see that there are Bar.prototype
constructions other than properties and "methods"?
Please answer my question, do I reason correctly, although judging by what I don’t understand, see a space somewhere! In general, I am waiting for answers from experienced programmers in this question, thank you for your attention! ps: please do not ask me questions, like "well, what do you think you yourself (privetdev incidentally)." If I understood everything, I would not take your time, dear! Thank!