理解jquery的$.extend()、$.fn.extend()【jQuery插件机制】

/**
 * 操作数据 | DOM 操作 
 * @description jQuery类添加类方法,可以理解为添加静态方法,将一个或多个对象的内容合并到目标对象
 * @use $.fn.zhang() | $([selector]).zhangs();
 */
$.extend($.fn, {
	zhangs: function() {
		console.log('zhangs');
	}
});
 
/**
 * @use $.fn();
 * @description 只有一个参数 
 * @link http://caibaojian.com/jquery-extend-and-jquery-fn-extend.html
 */
$.extend({
	zhang: function() {
		console.log('zhang');
	}
});

/**
 * DOM 操作
 * @description 对jQuery.prototype进得扩展,就是为jQuery类添加“成员函数”为jQuery扩展一个或多个实例属性和方法
 * @use $([selector]).fn();	
 */
$.fn.extend({
	zhangDom: function() {
		console.log('zhangDom');
	}
});

参考:https://www.runoob.com/jquery/misc-extend.html
原文地址:https://www.cnblogs.com/zhangchs/p/11798600.html