Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | - | - | ||||
LICENSE | D | 12-May-2024 | 765 | 16 | 12 | |
README.md | D | 12-May-2024 | 685 | 37 | 27 | |
package.json | D | 12-May-2024 | 1.3 KiB | 65 | 64 | |
wrappy.js | D | 12-May-2024 | 905 | 34 | 24 |
README.md
1# wrappy 2 3Callback wrapping utility 4 5## USAGE 6 7```javascript 8var wrappy = require("wrappy") 9 10// var wrapper = wrappy(wrapperFunction) 11 12// make sure a cb is called only once 13// See also: http://npm.im/once for this specific use case 14var once = wrappy(function (cb) { 15 var called = false 16 return function () { 17 if (called) return 18 called = true 19 return cb.apply(this, arguments) 20 } 21}) 22 23function printBoo () { 24 console.log('boo') 25} 26// has some rando property 27printBoo.iAmBooPrinter = true 28 29var onlyPrintOnce = once(printBoo) 30 31onlyPrintOnce() // prints 'boo' 32onlyPrintOnce() // does nothing 33 34// random property is retained! 35assert.equal(onlyPrintOnce.iAmBooPrinter, true) 36``` 37