source: trip-planner-front/node_modules/wrappy/README.md@ 76712b2

Last change on this file since 76712b2 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 685 bytes
Line 
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```
Note: See TracBrowser for help on using the repository browser.