Created
December 21, 2012 19:00
-
-
Save kossnocorp/4354995 to your computer and use it in GitHub Desktop.
Classical JS pitfall
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
@itrelease, просто javascript вообще не нужен. В топку его!
@whitequark программирование говно!
@itrelease ага, cachedMatches будет из последнего вызова.
createSelectors: ->
for name, selector of @els
do (name, selector) =>
cachedMatches = selector.match(/^cached (.+)/)
@['$' + name] = =>
if cachedMatches
@['$_' + name] ||= @$(cachedMatches[1])
else
@$(selector)
@milushov примерно вот так:
els:
new: '@new'
link: '@link'
tabs: '@tab'
input: 'cached @input'
@new
, @link
это алиас на [role='new']
.
@whitequark @itrelease и компьютеры отстой.
for
is probably the worst part of Coffee
@inossidabile maybe worst part of JS?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
А что хранится в @els? Можно примерчик?