AK-21/Graphite-Industrial-Intelligence
0
1# wrappy2 3Callback wrapping utility4 5## USAGE6 7```javascript8var wrappy = require("wrappy")9 10// var wrapper = wrappy(wrapperFunction)11 12// make sure a cb is called only once13// See also: http://npm.im/once for this specific use case14var once = wrappy(function (cb) {15 var called = false16 return function () {17 if (called) return18 called = true19 return cb.apply(this, arguments)20 }21})22 23function printBoo () {24 console.log('boo')25}26// has some rando property27printBoo.iAmBooPrinter = true28 29var onlyPrintOnce = once(printBoo)30 31onlyPrintOnce() // prints 'boo'32onlyPrintOnce() // does nothing33 34// random property is retained!35assert.equal(onlyPrintOnce.iAmBooPrinter, true)36```37 