Overlode
Javascript function overloading overloding utility. This utility's peculiar interface will make overloding functions easier for you.
Quick Start
Installing with npm.
> npm install overlode
Or download the source file overlode.js.
Write your first overloded function. Here we are using rubric.js to help with checks.
var overlode = ;var rubric = ; var createUser = ; ; // triggers the 1st overlode; // triggers the 2nd overlode; // triggers the 3rd (default) overlode
Supported Tests
;
Design Pattern
Good!
;
Function overlodes should always come in pairs in this order: array and function. The array should contain the tests for the arguments of the overlode, and the function is the function to use if the tests are satisfied.
Bad :(
;
Overlodes will be tested in the order they are written, from the top to the bottom. Whenever an array of tests pass it will try to run the function immediately afterwards. If it can't (not a funtion) it will reset and look for another test, and then another function.
Bad :(
;
If 2 functions are right after each other, the second function will be ignored as there are no tests preceding it. Unless, the function is the last argument in the overlode, in which case it is considered the default action and will be run if no other overlodes are run.
Bad :(
;
The number of tests should always match the number of arguments an action takes. Otherwise, the action will never get ran because tests will always fail.