I see so many functions like this:
form.prototype.smokerDisabled = function(){
return function(age) {
return age>=15 ? 'disabled="disabled"' : '';
};
};
what is the use of keeping the actual code inside another function and returing it. Instead it would have been written:
form.prototype.smokerDisabled = function(age){
return age>=15 ? 'disabled="disabled"' : '';
};
Please tell me the difference and use of the first approach. Thanks.
In this case I don't think there's any reason you would do that. The reason you would normally see a return function like that is to cause a closure that captures the state of an outside variable.
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