Click here to Skip to main content
15,947,958 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is a referenced module from douglas crockford's Javascript The good part.

Douglas said that objects are passed by reference and are never copied.
In the example below, a module is assigned.
Even though a module is an object, the same result as Object.create is coming out.
Douglas uses it like this:

var david = edge();

Why is a new object being allocated even though I don't use the create function?
If I have to create multiple objects based on edges (I'm making them now and I'm using them without problems), is there any problem?
Wouldn't it be better to use Object.create when creating multiple objects?

What I have tried:

edge = function(a, b){
   const name = a;
   const age = b;
   const html = name+" "+age;

   return {
          return html;

let david = edge('david', '23');
david.display(); // davis 23

let tom = Object.create(edge('tom', '52'));
tom.display(); // tom 53
Updated 23-May-22 23:58pm

1 solution

See JavaScript Objects[^], especially the section at:
Creating a JavaScript Object
With JavaScript, you can define and create your own objects.

There are different ways to create new objects:

Create a single object, using an object literal.
Create a single object, with the keyword new.
Define an object constructor, and then create objects of the constructed type.
Create an object using Object.create().
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900