OLOO?

by Artem

JavaScript

'use strict';

const Factory = {
	make(name, proto = null) {
  	return Object.create(proto).init(name);
  }
};

const Foo = {
	init(name) {
		this.name = name;
    return this;
  },
  sayHi() {
		console.log(this.name);
  }
};

const Bar = {
	greet() {
  	console.log('Hiiiiiiii');
  }
};

Object.setPrototypeOf(Bar, Foo);

Factory.make('bar', Bar).sayHi();