2014-11-05 07:08:12 +08:00
|
|
|
var wrappy = require('wrappy')
|
|
|
|
module.exports = wrappy(once)
|
2012-08-15 11:27:28 +08:00
|
|
|
|
|
|
|
once.proto = once(function () {
|
|
|
|
Object.defineProperty(Function.prototype, 'once', {
|
|
|
|
value: function () {
|
|
|
|
return once(this)
|
|
|
|
},
|
|
|
|
configurable: true
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
function once (fn) {
|
2013-10-25 00:21:59 +08:00
|
|
|
var f = function () {
|
|
|
|
if (f.called) return f.value
|
|
|
|
f.called = true
|
|
|
|
return f.value = fn.apply(this, arguments)
|
2012-08-15 11:27:28 +08:00
|
|
|
}
|
2013-10-25 00:21:59 +08:00
|
|
|
f.called = false
|
|
|
|
return f
|
2012-08-15 11:27:28 +08:00
|
|
|
}
|