Created
September 16, 2016 17:00
-
-
Save rewritten/07c4d1716bbf5cc7baa595258479d4be to your computer and use it in GitHub Desktop.
Example wrapper + functio + document:ready + turbolinks:load
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///////////////////////////////////////////////////////// | |
// Normal wrapper, using globals inside of it, but | |
// local variables and functions are not leaking out. | |
(function () { | |
// function to execute on load | |
var circle = function () { | |
// do stuff | |
}; | |
// attach to document:ready | |
$(circle); | |
// attach to turbolinks:load | |
$(document).on('turbolinks:load', circle); | |
})(); // end of wrapper | |
///////////////////////////////////////////////////////// | |
// more isolated version, pass dependencies as arguments so | |
// compressors can optimize better the name of the variables | |
(function (document, $) { | |
// function to execute on load | |
var circle = function () { | |
// do stuff | |
}; | |
// attach to document:ready | |
$(circle); | |
// attach to turbolinks:load | |
$(document).on('turbolinks:load', circle); | |
})(document, jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment