javascript - A way to pass a variable into a nested function -
is there way can pass information nested function ? problem want use jquery animate object being removed , after have remove object dom. theres no way pass information nested function. first though bellow work no luck,
tab = this.tab //this.tab dom element $(this.tab).effect('drop',null,null, function(tab) { $(tab).remove() })
people have suggested store element in global put function part of class , there can many objects may call function @ same time.
thankyou!
using closures should able do
var tab = this.tab $(tab).effect('drop', null, null, function() { $(tab).remove(); });
note tab
defined outside "nested function", since javascript supports closures, function can access variables defined in same scope itself. in other words, it'll able access tab
. note it's not this.tab
, since this
refers context in code called.
addendum: i'm not jquery-guy (weird, know), i'd imagine function pass effect()
executed in tab
element's context (i.e. inside function this
refers tab
element). if so, do
$(this.tab).effect('drop', null, null, function() { $(this).remove(); });
Comments
Post a Comment