Rahul Rahul - 6 months ago 51
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) {
e.stopPropagation();
e.preventDefault();

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

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

Answer

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.

Comments