jQuery扩展方法

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>jQuery扩展方法(调用自己写的方法)</title>
<meta charset="UTF-8">
</head>
<body>
<div>hello div</div>
<script src="jquery-3.4.1.js"></script>
<script>
//1.$.extend(),通过 $ 调用
// $.extend({
// getMax:function (a,b) {
// return a>b?a:b;
//
// }
// });
// alert($.getMax(6,4));
//2.$.fn.extend() ,$ 加 标签名 调用
// $.fn.extend({
// print:function () {
// console.log($(this).html())
// }
// });
// $('div').print();
//=======================================
// (function (a) {
// alert(a)
//
// })('come up');//come up
//以后写扩展方法 要将扩展方法放到一个匿名函数里面去
//私有域:避免与其他变量产生冲突,与外部实现解耦
(function () {
$.fn.extend({
print:function () {
console.log($(this).html())
}
});
})()
$('div').print();
</script>
</body>
</html>