javascript - coffeescript jquery method returning empty -



javascript - coffeescript jquery method returning empty -

i have next coffescript:

myelement = (-> $('.manyelements').eq(window.elemindex)) setelement = -> [...] myelement.addclass "class" window.elemindex ++

however getting unusual results. when debug setelements() , phone call myelement function returns empty []. when re-create paste myelement definition console, jquery object returned. why getting [] when set definition variable?

if @ compiled javascript, see jquery selector getting executed right away because wrapping in statement:

var myelement; myelement = (function() { homecoming $('.manyelements').eq(window.elemindex); })();

instead think want create function declaration:

myelement = -> $('.manyelements').eq(window.elemindex)

and phone call it

myelement().addclass('class')

edit:

if wanted avoid empty parenthetic phone call (to respond comment) couple different ways:

addclasstomyelement = (klass)-> $('.manyelements').eq(window.elemindex).addclass(klass) addclasstomyelement('class')

or

decorateelements = ($selector, klass='class')-> $selector.eq(window.elemindex).addclass(klass) decorateelements $('.manyelements') decorateelements $('.manyelements'), 'foo'

just ideas, using stuff default assignment in coffeescript create more flexible.

javascript jquery coffeescript

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -