Is there any way to set a variable equal to a function, but instead of the variable being equal to the function it is equal to the functions return value?
Searched for a bit on this without any success, it is most likely because I don't know how to phrase the question, but any help is appreciated, this is what I have :
Instead of having to set var ztype = zoom()
after the function, is there anyway for me to assign the return value to zoom
without an extra line of code?
var zoom = function(){ //can be set to Full / percentage / Image / left empty for native image size
var type = $('.carousel').attr('data-zoom');
if(!type){
type = $(that).attr('data-zoom');
}
return type;
}
var ztype = zoom();
If I'm understanding you correctly, you're trying to set a variable to the result of a function. This should do what you're hoping for;
var ztype = function(){ //can be set to Full / percentage / Image / left empty for native image size
var type = $('.carousel').attr('data-zoom');
if(!type){
type = $(that).attr('data-zoom');
}
return type;
}();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With