我遇到了一些 javascript 或 jQuery 函数,它们在方法的末尾有一个封闭的值或对象。例子:
(function ($) {
var delay = 0;
$.fn.translate3d = function (translations, speed, easing, complete) {
var opt = $.speed(speed, easing, complete);
opt.easing = opt.easing || 'ease';
translations = $.extend({ x: 0, y: 0, z: 0 }, translations);
return this.each(function () {
var $this = $(this);
$this.css({
transitionDuration: opt.duration + 'ms',
transitionTimingFunction: opt.easing,
transform: 'translate3d(' + translations.x + 'px, ' + translations.y + 'px, ' + translations.z + 'px)'
});
setTimeout(function () {
$this.css({
transitionDuration: '0s',
transitionTimingFunction: 'ease'
});
opt.complete();
}, opt.duration + (delay || 0));
});
};
})(jQuery);
或者
<script type="text/javascript">
(function (d, t) {
<snip>
})(document, 'script');
</script>
函数末尾的括号括起来的项目的目的是什么?我在 SO 上找到了几个答案,但没有任何解决办法。谢谢