# Generating IIFEs in Rails

DevFeed: [Generating IIFEs in Rails](<https://devfeed.tech/articles/generating-iifes-in-rails-40616.md>)

Original publisher: [Read original article](<https://eviltrout.com/blog/2013-02-25-iife-in-rails/>)

Published: 2013-02-25T00:00:00Z

Content type: tutorial

Language: en

Sources: [Robin Ward](<https://devfeed.tech/sources/robin-ward.md>)

Topics: [Rails](<https://devfeed.tech/topics/rails.md>), [JavaScript](<https://devfeed.tech/topics/javascript.md>), [function](<https://devfeed.tech/topics/function.md>)

Tags: [function](<https://devfeed.tech/tags/function.md>), [javascript](<https://devfeed.tech/tags/javascript.md>), [patches](<https://devfeed.tech/tags/patches.md>), [rails](<https://devfeed.tech/tags/rails.md>)

## AI overview

A tutorial explaining how to use the Rails asset pipeline to automatically wrap JavaScript files in Immediately Invoked Function Expressions (IIFEs), helping prevent variables from leaking into the surrounding scope.

## Source excerpt

Recently we ported Discourse from CoffeeScript to plain old Javascript. The process was straightforward since CoffeeScript spits out fairly good Javascript, although I did have to spend the better part of a day cleaning it up afterwards. (Note: we'd love any patches to further tidy up the generated Javascript.) One thing that CoffeeScript does by default that's nice is it wraps everything in an Immediately Invoked Function Expression (IIFE). If you're a Javascript developer you've almost certainly seen IIFEs before even if you haven't used the acroynm - they're very useful to ensure that any of your defined variables don't leak out.