Use JavaScript string as function name?

I need to call the function as follows:

var f = 'fadeOut'; $(v).f(s, function(){ $(v).css('visibility', 'hidden').css('position', 'absolute'); }); 

Can this be done simply?

+6
source share
1 answer

Yes

 var f = 'fadeOut'; $(v)[f](s, function(){ $(v).css('visibility', 'hidden').css('position', 'absolute'); }); 
+9
source

Source: https://habr.com/ru/post/912562/


All Articles