How to create an object with `Object.create()`?

// simple usage
let character = Object.create({}); = 'Son Goku';

// output: { name: 'Son Goku' }

// extended usage
// prototype object
const sayan = {
  hasTail: true,
  turnIntoSuperSayan() {
    console.log(`${} turned into a super sayan!`);

const character = Object.create(sayan); = 'Son Goku';
character.hasTail = false;

// output: "Son Goku turned into a super sayan!"

// output: { name: 'Son Goku', hasTail: false }

April 12th, 2020

# Object.create() - Create an object

Add to bookmarks

Object.create is a way to create an object by applying a prototype object as first parameter (can be an empty object as well).

The optional second parameter can be an object of properties which will be applied to the new object.

TL;DR: It's an alternative to new Object()