node/deps/npm/node_modules/once/once.js

21 lines
378 B
JavaScript
Raw Normal View History

module.exports = once
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)
}
2013-10-25 00:21:59 +08:00
f.called = false
return f
}