Function constructors are able to create objects in javascript but
I have a more basic question.
Declaring a plain function in Javascript using a “function declaration” such as
function Foo()
{
this.prop1 = 20;
//some code
}
Does this create an object internally in javascript heap with pointer as abc and prop1 as 20?
Or is it that the objects are created only when the function constructor is called
like
var a = new Foo() //This definately creates a new object
In javascript, all functions are objects.
You can do things like this:
A function object has all the same capabilities as a normal javascript object, but it can also do some additional things such as be used as a constructor and it has a few built-in properties. See the MDN page on Function objects for a description of the other properties/methods it has.