Last active
December 20, 2019 21:01
-
-
Save whitelizard/9656c3cc53da34997eccc30baba431b9 to your computer and use it in GitHub Desktop.
Functional style Factory in JavaScript
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
const makeCircle = (pos = [0, 0], r = 0) => { | |
let state = circle(pos, r); | |
return { | |
getState: () => state, | |
incHits: () => (state = incHits(state)), | |
setPos: pos => (state = setPos(state, pos)), | |
area: () => area(r), | |
intersect: c2 => { | |
let hit; | |
[hit, state] = intersect(state, c2.getState()); | |
if (hit) c2.incHits(); | |
return hit; | |
}, | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment