All the ways to create an object?


Hey everyone,

After finishing part 33 of Introduction to Objects I I'm still not entirely sure if there are 2 or 3 ways to create an object.
Mainly cause at part 33 of Objects in Review the explanatory text states: "Here, we have included a Circle object", while the object is made like this:

function Circle (radius) {};

In previous assignments I've learned these two ways:

var Circle = {};


var Circle = new Object();

The first one of that is literal notation and the second is constructor notation but I have no idea why they use function Circle (radius) {}; and what the name of it is.

Thanks in advance!


I was thinking that they put

function Circle(radius){};

as a circle creator because the statements inside the function statement help it make a circle. But I do not really know. :smiley:


Me neither, they did use {} which makes sense for an object but the way they create it doesn't make sense to me seeing all the previous exercises :stuck_out_tongue:


Well, remember. This is a function you're talking about

function Circle(radius){};

Object can really only be called like the below examples.

var Example = { };

var Example2 = new Object(); //So you're correct in assuming there are only 2 ways!

functions have a few other ways of being called, but generically it's not that hard to understand.

var Example3 = function(parameter) { ... }

function Example4(parameter) { ... }

I hope this clears that much up at least.


Ah thanks for explaining, so it's a way to create a function. Then the only thing I don't get is why they call it an object in the assignment but my main question has been answered thank you :smile: