Created
October 11, 2016 13:50
-
-
Save Kattoor/657d13e927c1807d0fcbbbe6df807e83 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
function overload(f1, f2) { | |
if (f1.length === f2.length) | |
throw new TypeError; | |
else | |
return function(...args) { | |
let params = Array.prototype.splice.call(arguments, 0); | |
if (params.length === f1.length) | |
return f1(...params); | |
else if (params.length === f2.length) | |
return f2(...params); | |
else | |
throw new TypeError; | |
} | |
} | |
var createVector = overload( | |
(a, b) => { return { x: a, y: b } }, | |
(length) => { return { x: length / 1.414, y: length / 1.414 } } | |
); | |
console.log(createVector(3, 4)); | |
console.log(createVector(7.07)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment