Skip to content
function overloading in javascript
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.gitignore
LICENSE
README.md
bower.json
gulpfile.js
mutate.js
mutate.min.js
package.json

README.md

mutate.js

mutate.js brings function overloading to javascript.

Sample

var sum = mutate(function() {
    return Array.prototype.reduce.call(arguments, function(memo, val) {
        return memo + val;
    }, 0);
})
.method(['array'], function(done, arr) {
    return done.apply(null, arr);
})
.method(['object'], function(done, obj) {
    var arr = [];
    for (var key in obj) {
        arr.push(obj[key]);
    }
    return done.apply(null, arr);
})
.close();

sum(1, 2, 3); // => 6
sum([1, 2, 3]); // => 6
sum({ prop1: 1, prop2: 2, prop3: 3}); // => 6

Installation

bower install mutate.js

License

Copyright (c) 2014 Simon Kusterer Licensed under the MIT license.

Something went wrong with that request. Please try again.