Skip to content

Instantly share code, notes, and snippets.

@kossnocorp
Created December 21, 2012 19:00
Show Gist options
  • Save kossnocorp/4354995 to your computer and use it in GitHub Desktop.
Save kossnocorp/4354995 to your computer and use it in GitHub Desktop.
Classical JS pitfall
class Amplifr.BaseView extends Backbone.View
constructor: ->
@createSelectors()
super
els: {}
createSelectors: ->
for name, selector of @els
cachedMatches = selector.match(/^cached (.+)/)
@['$' + name] = =>
if cachedMatches
@['$_' + name] ||= @$(cachedMatches[1])
else
@$(selector)
@kossnocorp
Copy link
Author

@inossidabile maybe worst part of JS?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment