【发布时间】:2014-08-07 02:44:36
【问题描述】:
我想覆盖我的 JS 库中的一个函数。我有以下代码结构
插件.js
function Plugin(elements, options) {
'use strict';
return this.init(elements, options);
}
if (typeof module === 'object') {
module.exports = Plugin;
}
(function (window, document) {
'use strict';
Plugin.prototype = {
defaults: {
showFlag: false,
indent: true
},
insertDiv: function(parentElement){
//some jquery code;
},
insertCustomData: function(parentElement){
//some jquery code
this.insertDiv(parentElement);
},
};
}(window, document));
test.html
<html>
<body>
<div id="test">
<p>Test Content</p>
</div>
</body>
<script src="plugin.js"/>
<script type="text/javascript">
var plugin = new Plugin('test', {showFlag: true, indent:false});
</script>
</html>
我想覆盖 plugin.js 中的 insertDiv() 函数,并在我的 test.html 中提供我自己的 insertDiv() 实现
所以当我从 insertCustomData() 调用 insertDiv() 时,它应该在我的 test.html 中而不是在 plugin.js 中执行该函数
有什么方法可以实现吗?
提前致谢。
【问题讨论】:
标签: javascript jquery jquery-plugins