0
我的项目中有一个jQuery模块模式。我不理解它在做什么以及它为什么在做。Jquery模块模式
存在是由
(function($) {
$.fn.skInit = function() {
return this.each(function(i,element) {
var e = jQuery.Event('skInit');
e.container = $(element);
$(':root').trigger(e);
});
};
$.skInit = function(handler) {
$(':root').on('skInit',handler);
};
}(jQuery));
and skInit.cs jquery file
$(document).ready(function() {
'use strict';
//console.log('skInit');
$(':root').skInit();
});
and in remaining js files events are attached as follow. one of js file example
$(document).ready(function() {
'use strict';
$.skInit(function (e) {
e.container.find('.csSpotTeaserInner').csSpotlightTeaserToggle();
e.container.find(".sliderBarDiv").mCustomScrollbar();
});
});
为什么要这样设计的图案以这种方式writtern自定义插件jquery.skInit.js ...它如何优化和提高性能......如果任何人都可以请解释。我的项目是grunt项目,其中所有的javascript都是单独的bottom.js脚本。
还有你的代码使用很多模式来解释的过程。你具体提到哪一个? – Bergi
我只是想知道制作skInit()函数的益处 –
相比于什么?在挂钩事件的每个模块中写出'('skInit',function(e){...})''($:':root')。 – Bergi