프로젝트

일반

사용자정보

통계
| 개정판:

root / HServer / 00.Server / 00.Program / node_modules / wrappy / README.md

이력 | 보기 | 이력해설 | 다운로드 (685 Bytes)

1
# wrappy
2

    
3
Callback wrapping utility
4

    
5
## USAGE
6

    
7
```javascript
8
var 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
14
var 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

    
23
function printBoo () {
24
  console.log('boo')
25
}
26
// has some rando property
27
printBoo.iAmBooPrinter = true
28

    
29
var onlyPrintOnce = once(printBoo)
30

    
31
onlyPrintOnce() // prints 'boo'
32
onlyPrintOnce() // does nothing
33

    
34
// random property is retained!
35
assert.equal(onlyPrintOnce.iAmBooPrinter, true)
36
```