Name: js-handler/node_modules/restify/node_modules/once/README.md
| 1: | # once |
| 2: | |
| 3: | Only call a function once. |
| 4: | |
| 5: | ## usage |
| 6: | |
| 7: | ```javascript |
| 8: | var once = require('once') |
| 9: | |
| 10: | function load (file, cb) { |
| 11: | cb = once(cb) |
| 12: | loader.load('file') |
| 13: | loader.once('load', cb) |
| 14: | loader.once('error', cb) |
| 15: | } |
| 16: | ``` |
| 17: | |
| 18: | Or add to the Function.prototype in a responsible way: |
| 19: | |
| 20: | ```javascript |
| 21: | // only has to be done once |
| 22: | require('once').proto() |
| 23: | |
| 24: | function load (file, cb) { |
| 25: | cb = cb.once() |
| 26: | loader.load('file') |
| 27: | loader.once('load', cb) |
| 28: | loader.once('error', cb) |
| 29: | } |
| 30: | ``` |
| 31: | |
| 32: | Ironically, the prototype feature makes this module twice as |
| 33: | complicated as necessary. |
