Skip to content

Instantly share code, notes, and snippets.

@cballenar
Created January 14, 2022 16:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cballenar/c9c3c89f358ed52191b8d139e5ae2aa0 to your computer and use it in GitHub Desktop.
Save cballenar/c9c3c89f358ed52191b8d139e5ae2aa0 to your computer and use it in GitHub Desktop.
Visual Code Snippet for Drupal's Immediately Invoked Function Expression (IFFE). Add to your JS snippets configuration in VS and call it with `drif`.
"Drupal IFFE": {
"prefix": "drif",
"body": [
"/**",
"* @name ${1:ScriptName}",
"* @description ${2:Script description.}",
"* @param {string} input",
"* @returns {string} output",
"*/",
"(function ($, window, Drupal) {",
" Drupal.behaviors.blockSettingsSummary = {",
" attach: function attach() {",
" ${3}",
" }",
" };",
"})(jQuery, window, Drupal);"
],
"description": "Drupal's recommended Immediate Invoked Function Expression. Source: https://drupalize.me/tutorial/wrap-your-custom-javascript-closure?p=2512."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment