Why should we use Object.create over new Object

Why should we use Object.create over new Object
0.0 0

#1
function Person(name) { 
    this.name = name; 
}

let bob = new Person('Bob');

let Rooba = Object.create(Person.prototype);

I know these are the two ways to instantiate the new Object but why everyone is suggesting to use Object.create over new Object?

Even in free-code-camp challenge also they have mentioned that there is a problem using new Object.

===============================================
And one more question is why we need @params? is this purely to understand code or is there any advantage of writing the following way.

/**
 * Get given number of cups of tea.
 * @param {number} numOfCups Number of required cups of tea.
 * @return {Array<string>} Given amount of tea cups.
 **/

#2

Hi @Randore

  1. It’s almost the same thing but not the same thing :slight_smile:
    I suggest you read this post https://medium.com/@jonathanvox01/understanding-the-difference-between-object-create-and-the-new-operator-b2a2f4749358
    You will note the using of “this” when you do a new() and the constructor matter.

  2. For annotations “@” it’s simply for documentation generator like JSDoc for example.
    For these types of annotations (between comment tags) there is no effect on your code which is not the fact when you see @observer for instance (not between comment tags) as you can see in MobX (for React or others).
    In this last case, you have runtime effects.


#3

I think you’re getting confused about what they’re talking about.

Object.create is useful for some specific things, but in you’re example and those like it (most cases) you will use new. The argument against that is that stuff breaks if you forget to write new, but there are ways to mitigate that.

What is to be avoided is using new Object() instead of {}