3 Only call a function once.
8 var once = require('once')
10 function load (file, cb) {
13 loader.once('load', cb)
14 loader.once('error', cb)
18 Or add to the Function.prototype in a responsible way:
21 // only has to be done once
22 require('once').proto()
24 function load (file, cb) {
27 loader.once('load', cb)
28 loader.once('error', cb)
32 Ironically, the prototype feature makes this module twice as
33 complicated as necessary.
35 To check whether you function has been called, use `fn.called`. Once the
36 function is called for the first time the return value of the original
37 function is saved in `fn.value` and subsequent calls will continue to
41 var once = require('once')
45 var stream = createStream()
46 stream.once('data', cb)
47 stream.once('end', function () {
48 if (!cb.called) cb(new Error('not found'))