source: imaps-frontend/node_modules/reusify/reusify.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 454 bytes
Line 
1'use strict'
2
3function reusify (Constructor) {
4 var head = new Constructor()
5 var tail = head
6
7 function get () {
8 var current = head
9
10 if (current.next) {
11 head = current.next
12 } else {
13 head = new Constructor()
14 tail = head
15 }
16
17 current.next = null
18
19 return current
20 }
21
22 function release (obj) {
23 tail.next = obj
24 tail = obj
25 }
26
27 return {
28 get: get,
29 release: release
30 }
31}
32
33module.exports = reusify
Note: See TracBrowser for help on using the repository browser.