Rahul Rahul - 5 months ago 28x
Javascript Question

Javascript Questions on the function - IIFE

I was asked to ask another question and link it to this thread.
How add mandatory dropdown field in Touch UI

My question is what:
can somebody tell me what is the end line of the javascript function is doing.

})(document, Granite.$, Granite.author);

is it some kind of namespacing.

For your reference i am attaching the Javascript code.

(function (document, $, ns) {
"use strict";

$(document).on("click", ".cq-dialog-submit", function (e) {

var $form = $(this).closest("form.foundation-form"),
title = $form.find("[name='authoringMode']").val(),
message, clazz = "coral-Button ";

title: Granite.I18n.get("Invalid Input"),
message: "Please Check Values",
actions: [{
id: "CANCEL",
text: "CANCEL",
className: "coral-Button"
callback: function (actionId) {
if (actionId === "CANCEL") {
})(document, Granite.$, Granite.author);


This is what we otherwise call a self-invoking function:

(function (document, $, ns) { ...
})(document, Granite.$, Granite.author);

and those ("document, Granite...etc) are arguments being passed to that very same function.