[英]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
如何在Touch UI中添加必填下拉字段
My question is what: can somebody tell me what is the end line of the javascript function is doing. 我的问题是:有人可以告诉我javascript函数的结束行是什么。
})(document, Granite.$, Granite.author);
is it some kind of namespacing. 这是某种命名空间吗?
For your reference i am attaching the Javascript code. 供您参考,我附上Javascript代码。
(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);
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. 而那些(“文档,Granite ...等”)是传递给该函数的参数。
})(document, Granite.$, Granite.author);
passes parameters to function, defining document
as document
, Granite.$
as $
and Granite.author
as ns
within the function expression at 在函数表达式
Granite.author
参数传递给函数,将document
定义为document
,将Granite.$
为$
并将Granite.author
为ns
(function (document, $, ns) {
eg, 例如,
var obj = { $:jQuery, author:"abc" }; (function(document, $, ns) { "use strict"; console.log($, ns) }(document, obj.$, obj.author))
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.