jquery selector cache

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
$_ = (selector, reset = false) ->
@cache ?= {}
if reset
if selector?
delete @cache[selector]
else
@cache = {}
return true
return @cache[selector] if @cache[selector]?
obj = $(selector)
@cache[selector] = obj
return obj