Permalink
Browse files

simplify once, and do not wait a tick before firing

  • Loading branch information...
1 parent c37766e commit 82c6713cb8f0331eb14291f909f53b1ca06456d3 @marcuswestin committed May 22, 2013
Showing with 4 additions and 9 deletions.
  1. +4 −9 once.js
View
13 once.js
@@ -1,13 +1,8 @@
module.exports = function once(fn) {
- var timeout
- var args
+ var fired = false
return function() {
- args = arguments
- if (timeout) { return }
- timeout = setTimeout(function() {
- fn.apply(this, args)
- timeout = null
- args = null
- }, 0)
+ if (fired) { return }
+ fired = true
+ fn.apply(this, arguments)
}
}

0 comments on commit 82c6713

Please sign in to comment.