有人可以为我清楚地解释以下功能吗?更重要的是,在嵌套函数首先调用的每个函数中?我已经在线阅读了几个教程,并且在通过一些开源项目时设法识别以下内容。
功能1
(function (factory) {
if (typeof define === 'function' && define.amd) {
define(['jquery'], factory);
} else if (typeof exports === 'object') {
factory(require('jquery'));
} else {
factory(jQuery);
}
})(function ($) {
function Avatar($element) {
this.init();
}
Avatar.prototype = {
constructor: Avatar,
init: function () {
}
};
$(function () {
return new Avatar($('#avatar'));
});
});
功能2
!function($) {
"use strict";
var Nestable = function() {};
Nestable.prototype.updateOutput = function (e) { },
Nestable.prototype.init = function() { },
$.Nestable = new Nestable, $.Nestable.Constructor = Nestable
}(window.jQuery),
function($) {
"use strict";
$.Nestable.init()
}(window.jQuery);