mirror of https://github.com/lukechilds/node.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
346 B
20 lines
346 B
12 years ago
|
module.exports = once
|
||
|
|
||
|
once.proto = once(function () {
|
||
|
Object.defineProperty(Function.prototype, 'once', {
|
||
|
value: function () {
|
||
|
return once(this)
|
||
|
},
|
||
|
configurable: true
|
||
|
})
|
||
|
})
|
||
|
|
||
|
function once (fn) {
|
||
|
var called = false
|
||
|
return function () {
|
||
|
if (called) return
|
||
|
called = true
|
||
|
return fn.apply(this, arguments)
|
||
|
}
|
||
|
}
|