I’m confused about the different ways to declare functions inside a constructor function.
function ClassName() {
this.one = function() {};
var two = function() {};
three = function() {};
}
I know one is public and can be called by the outside and two is private. What are the semantics for three?
The example as you have provided would be a syntax error, as you need to use
=for assignment in that context.threeif used with the correct assignment operator would be a global function that would exist outside of that scope. When you omit thevarkeyword, the variable is assigned a property of the global object, which iswindowin a browser.jsFiddle.
When using
var, they become properties of the VariableObject in the execution context. You use them as normal variables.Further Reading.