# 封装
# jquery封装
/*
* author dujun
* date 2020-06-12
* plugin 封装demo
*/
(function ($) {
"use strict";
$.fn.test = function (options) {
//如果是初始化组件
options = $.extend({}, $.fn.test.defaults, options || {});
var _this = $(this);
_this.add = function(data){
var ds = data+options.data[2];
$("#"+options.id).html(ds)
};
return _this.add(options.data[0]);
}
$.fn.test.defaults = {
id:'Id',
data:[1,2,3],
}
})(jQuery);
//调用
<body>
123 <br>
tb<span id="tb"></span><br>
Id <span id="Id"></span><br>
Id2 <span id="Id2"></span>
</body>
<script src="statics/js/plugin.js"></script>
<script>
//$.test.add(1);
$(document).ready(function () {
$("#tb").test({
id:'Id',
data:[3,4,5],
})
});
console.log($.fn)
</script>
# module.exports封装 [参考](exports,module.exports和export,export default)
module.exports = {
a:'这是准备导入的参数a1',
foo2:function(){
console.log(this.a)
},
};
import obj from '../../assets/js/**';
//let obj = require('../../assets/js/**');
← 堆和栈 /js/待封装方法.html →