exotic-object

1.0.0 • Public • Published

Exotic Object

Description

In JavaScript, an exotic object is a type of object that has a non-standard behavior.

With the help of this library, we can create exotic objects with custom behavior for each operation that will be applied to the object.

Installation

npm install exotic-object

Usage Examples

Let's create an exotic object with only the function call operator defined, and any other operation on the object will cause an error.

const {exoticObject} = require('exotic-object');

const obj = exoticObject({
    operation: {
        call: (state, arguments, thisArg) => {
            return "I am the result of the call"
        }
    }
});

// correct usage
const result = obj(); // "I am the result of the call"

// wrong usage
obj.abc = "Hello"; // SetNotAllowedError: Set is Not Allowed
obj.abc;           // GetNotAllowedError: Get is Not Allowed

Contributing

Read our contributing guide to learn about our development process.

Code of Conduct

This project has adopted the Contributor Covenant as its Code of Conduct, and we expect project participants to adhere to it. Please read the full text so that you can understand what actions will and will not be tolerated.

Authors

License

MIT License

Package Sidebar

Install

npm i exotic-object

Weekly Downloads

2

Version

1.0.0

License

MIT

Unpacked Size

20.3 kB

Total Files

10

Last publish

Collaborators

  • ruben_arushanyan