factory-knows

0.1.2 • Public • Published

factory-knows 🏭👃

Build Status Coverage Status Greenkeeper badge WebReflection status

An instanceof alternative for non class based, factory oriented, programming.

import $ from 'factory-knows';
// OR
// const $ = require('factory-knows');
// OR
// <script src="https://unpkg.com/factory-knows"></script>
// <script>const Factory = factoryKnows(...);</script>

const Person = $((name = 'anonymous') => ({
  birthday() {
    this.age++;
    console.log('🎉');
  },
  age: 0,
  name
}));

const me = Person('A G');
Person.knows(me); // true
me.birthday();    // 🎉

const {assign} = Object;
const Employee = $((company, name) => assign(
  Person(name),
  {
    levelUP() {
      this.experience++;
      console.log('🤝');
    },
    experience: 0,
    company
  }
));

const roadrunner = Employee('ACME', 'RoadRunner');
Person.knows(roadrunner);   // true
Employee.knows(roadrunner); // true
roadrunner.levelUP();       // 🤝
roadrunner.experience;      // 1

Package Sidebar

Install

npm i factory-knows

Weekly Downloads

1

Version

0.1.2

License

ISC

Unpacked Size

6.1 kB

Total Files

8

Last publish

Collaborators

  • webreflection