You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

reusify.js 454B

123456789101112131415161718192021222324252627282930313233
  1. 'use strict'
  2. function reusify (Constructor) {
  3. var head = new Constructor()
  4. var tail = head
  5. function get () {
  6. var current = head
  7. if (current.next) {
  8. head = current.next
  9. } else {
  10. head = new Constructor()
  11. tail = head
  12. }
  13. current.next = null
  14. return current
  15. }
  16. function release (obj) {
  17. tail.next = obj
  18. tail = obj
  19. }
  20. return {
  21. get: get,
  22. release: release
  23. }
  24. }
  25. module.exports = reusify