Giter Site home page Giter Site logo

overridable's Introduction

Overridable

Make JavaScript overridable.

Introduction

JavaScript does not support overriding when we declare a function since JavaScript will cover the newer one with the older one. Thus, I made this package in order to enable this feature.

Usage

npm i overridable -S

overridable(): Overridable

Creates overridable object, includes

{
  // All of the function with different arguments
  functions: Array<Function>,
  // Add a function with a different arguments object
  add: Function<Function>,
  // If you add all the overrides, use this to get the final function
  result: Function;
};

add(fn: Function): Overridable

Add a function to overridable object.

overridable().add(() => {});

result(): Function

Returns the final function. If you add all the overrides, use this to get the final function.

const foo = overridable().add(() => {}).result();
foo();

Example

const overridable = require('overridable');

const foo = overridable()
  .add(a => Math.pow(a, 2))
  .add((a, b) => a * b)
  .add((a, b, c) => a + b + c)
  .result();

console.log(foo(3)); // 9
console.log(foo(2, 3)); // 6
console.log(foo(1, 2, 3)); // 6
console.log(foo(1, 2, 3, 4)); // Error

TODO

  • Unit test support
  • ES 2015 support
  • NPM registry

Issues

I am very glad if you can find some issues in this project. If you do find something strange or some questions, please make a issue at https://github.com/lenconda/overridable/issues.

Contribute

Thank you for your interest in this project. You are welcomed to make contributions on it. However, before you starting your contribution work, please read the following advice:

  • Read the README first
  • Understand what changes you want to make
  • Look through the issue list and check if there's an issue to solve the same problem
  • Publish or/and redistribute this project should under MIT license

If you decide to write your code in this project, you can fork this project as your own repository, check out to a new branch, from the newest code at master branch. The new branch would be your work bench.

If you want to commit your changes, you are supposed to make an pull request, once you submit the request, the review process will start, if the code meets the requirements, the pull request will pass, and then your code will be in the project. If the request does not be passed, please contact [email protected] or [email protected].

License

MIT © Lenconda

overridable's People

Contributors

lenconda avatar

Stargazers

 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.