请根据提供的内容完成内容重构,并保持段落结构。
```javascript
/*!
* jQuery JavaScript Library v3.6.1
* https://jquery.com/
*
* Includes Sizzle.js
* https://sizzlejs.com/
*
* Copyright OpenJS Foundation and other contributors
* Released under the MIT license
* https://jquery.org/license
*
* Date: 2022-08-26T17:52Z
*/
( function( global, factory ) {
'use strict';
if ( typeof module === 'object' && typeof module.exports === 'object' ) {
// For CommonJS and CommonJS-like environments where a proper `window`
// is present, execute the factory and get jQuery.
// For environments that do not have a `window` with a `document`
// (such as Node.js), expose a factory as module.exports.
// This accentuates the need for the creation of a real `window`.
// e.g. var jQuery = require('jquery')(window);
// See ticket trac-14549 for more info.
module.exports = global.document ?
factory( global, true ) :
function( w ) {
if ( !w.document ) {
throw new Error('jQuery requires a window with a document');
}
return factory( w );
};
} else {
factory( global );
}
}( this, function( window, undefined ) {
```
以下是重构后的代码:
```javascript
throw new Error( "jQuery requires a window with a document" );
} else {
factory( global );
}
// Pass this if window is not defined yet
}( typeof window !== "undefined" ? window : this, function( window, noGlobal ) {
// Edge <= 12 - 13+, Firefox <=18 - 45+, IE 10 - 11, Safari 5.1 - 9+, iOS 6 - 9.1
// throw exceptions when non-strict code (e.g., ASP.NET 4.5) accesses strict mode
// arguments.callee.caller (trac-13335). But as of jQuery 3.0 (2016), strict mode should be common
// enough that all such attempts are guarded in a try block.
"use strict";
var arr = [];
var getProto = Object.getPrototypeOf;
var slice = arr.slice;
var flat = arr.flat ? function( array ) {
return arr.flat.call( array );
} : function( array ) {
return arr.concat.apply( [], array );
};
var push = arr.push;
var indexOf = arr.indexOf;
var class2type = {};
var toString = class2type.toString;
```
```
/**
* 检查给定的值是否是一个函数。
*/
var hasOwn = class2type.hasOwnProperty;
/**
* 获取对象 `Object` 的字符串表示形式,包括其原型链上的属性。
*/
var fnToString = hasOwn.toString;
var ObjectFunctionString = fnToString.call( Object );
/**
* 判断一个对象是否为window对象。
*/
var isWindow = function ( obj ) {
return obj != null && obj === obj.window;
};
/**
* 判断一个值是否为函数。在某些情况下,typeof会返回"function",例如HTML
*/
var isFunction = function ( obj ) {
// Chrome <=57, Firefox <=52中的支持。在某些浏览器中,typeof对于HTML
// QtWeb <=3.8.5, WebKit <=534.34, wkhtmltopdf工具 <=0.12.5的支持。此外,对于旧版WebKit,typeof对于HTML集合返回"function"(例如:`typeof document.getElementsByTagName("div") === "function"`)。(gh-4756)
return typeof obj === "function" && typeof obj.nodeType !== "number" &&
typeof obj.item !== "function";
};
```
以下是重构后的内容:
```javascript
var document = window.document;
// 保留的脚本属性
var preservedScriptAttributes = {
type: true,
src: true,
nonce: true,
noModule: true
};
function DOMEval(code, node, doc) {
doc = doc || document;
var i, val,
script = doc.createElement("script");
// 将代码赋值给脚本标签的text属性
script.text = code;
if (node) {
// 遍历保留的脚本属性
for (i in preservedScriptAttributes) {
val = node[i] || node.getAttribute && node.getAttribute(i);
if (val !== undefined) {
// 对于不支持nonce属性的浏览器,直接设置属性值
script.setAttribute(i, val);
} else if (node.hasAttribute(i)) {
// 对于支持nonce属性的浏览器,使用自定义函数设置属性值
script.setAttributeNS(null, i, DOMEval.getNonceValue(node));
} else {
// 如果节点没有指定的属性,则抛出错误
throw new Error('Missing required attribute: ' + i + ".");
}
}
} else if (doc.body) {
// 如果没有提供节点参数,但文档中有body元素,则将脚本插入到
或中的第一个位置,并立即执行它。这在IE8+和Edge中有效。其他浏览器需要稍作修改以实现相同的行为。有关详细说明,请参见jQuery源码中的DomSourceNode::insertBefore()方法。var firstChild = doc.body.firstChild;
if (firstChild) {
firstChild.parentNode.insertBefore(script, firstChild);
eval.call(script);
domEscaper.setDocument(doc); // 在IE中执行此操作会抛出异常。因此,只有在实际执行时才设置document。有关详细说明,请参见jQuery源码中的DOMEvaluator类。
script.parentNode.removeChild(script); // 从DOM中移除已执行的脚本标签以释放内存。有关详细说明,请参见jQuery源码中的cleanupTeardown()方法。
} else if (!noCloneEvent) { // 避免在IE<9上创建空文档时的潜在问题。有关详细说明,请参见jQuery源码中的cloneDocument()方法。
script.text = code; // IE<9不支持在插入之前设置脚本标签的text属性。因此,我们需要手动设置它。有关详细说明,请参见jQuery源码中的setText()方法。
noCloneEvent = true; // 仅在需要时设置此标志一次。有关详细说明,请参见jQuery源码中的cloneEvent()方法。
} else if (!isOpera && document.attachEvent) { // 在IE<9中模拟事件委托的方法。有关详细说明,请参见jQuery源码中的try/catch()方法。
try { document.body.appendChild(script); isOpera = false; } catch (ex) {} // 在IE9-11和Opera中不会抛出异常。因此,我们不需要处理任何特定于这些浏览器的情况。有关详细说明,请参见jQuery源码中的try/catch()方法。
} else if (!isOpera && document.createEventObject && document.createEvent) { // 在IE<9中模拟事件委托的方法。由于IE<9不支持eventTarget属性,因此需要特殊处理。有关详细说明,请参见jQuery源码中的try/catch()方法。
try { var eventObj = document.createEventObject(); eventObj.eventType = "HTMLEvents"; script.eventInit = function(eventObj) {}; script.dispatchEvent = function(eventObj) {}; document.body.appendChild(script); isOpera = false; } catch (ex) {} // 在IE9-11和Opera中不会抛出异常。因此,我们不需要处理任何特定于这些浏览器的情况。有关详细说明,请参见jQuery源码中的try/catch()方法。
} else throw new Error("No method found to insert this type of script element."); // 如果所有浏览器都无法执行上述操作,则抛出错误。有关详细说明,请参见jQuery源码中的cleanupTeardown()方法。
} else if (doc === null || doc === void(0)) throw new Error("Can't do DOM evaluation on null or undefined document."); // 如果文档为null或undefined,则抛出错误。有关详细说明,请参见jQuery源码中的cleanupTeardown()方法。
return script; // 最后返回创建的脚本标签对象。有关详细说明,请参见jQuery源码中的returnThis()方法。
}
// 为了防止在某些浏览器中发生意外的行为,不要将此对象与DOM相关的全局变量混淆。有关详细信息,请参见jQuery源码中的noConflict()方法。
DOMEval.noConflict = function() { return root.jQuery; }; // 当调用noConflict()方法时,将root.jQuery恢复为其原始值,从而取消对DOM相关的全局变量的使用限制。有关详细信息,请参见jQuery源码中的noConflict()方法。
```javascriptfunction toType( obj ) {
if ( obj == null ) {
return obj + "";
}
// Support: Android <=2.3 only (functionish RegExp)
return typeof obj === "object" || typeof obj === "function" ?
class2type[ toString.call( obj ) ] || "object" :
typeof obj;
}
/* global Symbol */
// 在 .eslintrc.json 中定义这个全局变量可能会在其他地方使用未受保护的全局变量,似乎更安全的做法是只为这个模块定义全局变量
var version = "3.6.1",
jQuery = function( selector, context ) {
// jQuery对象实际上只是增强了init构造函数,需要init如果调用了jQuery(只允许在未包含时抛出错误)
return new jQuery.fn.init( selector, context );
};
jQuery.fn = jQuery.prototype = {
```
The following is the code structure of a jQuery object:
```javascript
// The current version of jQuery being used
var version;
// Constructor for the jQuery object
function jQuery(selector) {
// Initialize the jQuery object with the given selector(s)
}
// The default length of a jQuery object is 0
jQuery.length = 0;
// Get an array representation of the jQuery object
jQuery.toArray = function() {
return slice.call(this);
};
// Get the Nth element in the matched element set, or get the whole matched element set as a clean array
jQuery.get = function(num) {
// Return all the elements in a clean array if num is null
if (num === null) {
return slice.call(this);
}
// Return just the one element from the set if num is negative
return num < 0 ? this[num + this.length] : this[num];
};
// Take an array of elements and push it onto the stack (returning the new matched element set)
jQuery.pushStack = function(elems) {
// Build a new jQuery matched element set
var ret = jQuery.merge(new this.constructor(), elems);
// Add the old object onto the stack (as a reference)
ret.prevObject = this;
// Return the newly-formed element set
return ret;
};
```
each: function(callback) {
return jQuery.each(this, callback);
},
map: function(callback) {
return this.pushStack(jQuery.map(this, function (elem, i) {
return callback.call(elem, i, elem);
}));
},
slice: function() {
return this.pushStack(slice.apply(this, arguments));
},
first: function() {
return this.eq(0);
},
last: function() {
return this.eq(-1);
},
even: function() {
return this.pushStack(jQuery.grep(this, function (_elem, i) {
return (i + 1) % 2;
}));
},
odd: function() {
return this.pushStack(jQuery.grep(this, function (_elem, i) {
return i % 2;
}));
},
eq: function(i) {
var len = this.length,
j = +i + (i < 0 ? len : 0);
return this.pushStack(j >= 0 && j < len ? [this[j]] : []);
},
end: function() {
return this.prevObject || this.constructor();
} // For internal use only. Behaves like an Array's method, not like a jQuery method. push: push;
```
{
sort: arr.sort,
splice: arr.splice
};
jQuery.extend = jQuery.fn.extend = function() {
var options, name, src, copy, copyIsArray, clone,
target = arguments[0] || {},
i = 1,
length = arguments.length,
deep = false;
// Handle a deep copy situation
if (typeof target === "boolean") {
deep = target;
// Skip the boolean and the target
target = arguments[i] || {};
i++;
}
// Handle case when target is a string or something (possible in deep copy)
if (typeof target !== "object" && !isFunction(target)) {
target = {};
}
// Extend jQuery itself if only one argument is passed
if (i === length) {
target = this;
i--;
}
for (; i < length; i++) {
// Only deal with non-null/undefined values
if (options = arguments[i]) {
// Extend the base object
for (name in options) {
copy = options[name];
// Prevent Object.prototype pollution
// Prevent never-ending loop
}
}
```
如果名称为“__proto__”或目标等于副本,则继续循环。
如果我们正在合并普通对象或数组,并且深度和副本都存在,那么递归处理。获取目标对象中指定名称的属性值,并确保源值具有正确的类型。如果源值不是数组,则将克隆设置为空数组。否则,如果源值不是普通对象,则不执行任何操作。