jquery - JavaScript variable isn't known to inline function (scoping?) -


i have following jquery:

function getselectedcheckboxids(classname) {     var ln = classname.length;     return $('.' + classname + ':checked').map(function() {         return this.id.substring(ln);     }).get(); } 

the variable ln unknown inside scope of map function.
scoping rules here , how can pass ln value inner function?

the variable ln not unknown within scoping function (working live here), makes think is? because function closes on execution context of call getselectedcheckboxids, ln accessible it.

the scoping rules simple, they're unlike many other languages. more in this article closures, basically, function "closes over" (has reference to) data in scope in execution context in created. in case, anonymous function created inside execution context of call getselectedcheckboxids , has access arguments , variables defined in context (classname , ln, in case), inherited enclosing contexts (including global execution context, how javascript global variables).


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -