1
The difference is in the instances you create of this "class". The instance only exposes what is in this
her or has been inherited:
var objeto = new Func();
objeto.fn_this(); // "this"
objeto.fn_func(); // ERRO - objeto.fn_func is not a function
objeto.fn_var(); // ERRO - objeto.fn_var is not a function
So basically you should put in this
what you want exposed (but often it’s better to put in the prototype). The other two forms you use for what is "private", which can only be accessed on scope of the builder.
Also worth understanding the difference between function fn(){}
and var fn = function(){}
, and yet why fn_func
and fn_var
can be called from within fn_this
. See also: What is and how the context works in Javascript?
@rubStackOverflow The context of that question is different, it’s about when to use
var
versus omit thevar
.– bfavaretto