I am wondering if the self invoking function as displayed below, mainly the part of using the same function twice ('foo')('bar')
, would ever be seen as a good practice?
And more important, is there a good reason to use this? Personally in this particular example I would rather go for multiple attributes and loop those.
The HTML is just filler.
<!DOCTYPE html>
<meta charset='utf-8'>
<title>Foo Bar Foobar</title>
<p id='foo'>Foo</p>
<p id='bar'>Bar</p>
<p>Foobar</p>
<script>
(function foobar(id) {
var element = document.getElementById(id);
element.style.color = 'red';
element.style.textIndent = '10px';
// Return self
return foobar;
})('foo')('bar');
</script>