gstackoverflow gstackoverflow - 8 months ago 48
Javascript Question

difference between functionName() and

I research functional inheritance in javascript.
According the article I have read I have wrote the code:

function Base(){
var enableVar = true

this.enable = function(){
enableVar = true;
this.disable = function(){
enableVar = true;

function Child(){;

new Child().enable();

this code works properly and I see message in console.

but I don't understand row:;

for me it is
function invocation with
replaced with
thus it is same with

But looks like my state is wrong. I see error:

VM898:62Uncaught TypeError: (intermediate value).enable is not a function(…)

Please clarify difference for me.

Answer Source calls functionName normally, with one main difference: Inside of functionName, this refers to obj. Normally this refers to window, but making this reference obj is very good for inheritance because you can just keep on using this throughout all of your constructors.