Javascript 如何扩展jquery注释?
我使用允许在我的网站上发表评论。这很好,但我想对它的工作方式做一些更改 但是,我不想直接在中对jquery注释进行更改,而是希望将它们放在不同的文件中,并尽可能使用我自己的函数扩展/修改Javascript 如何扩展jquery注释?,javascript,jquery,jquery-plugins,Javascript,Jquery,Jquery Plugins,我使用允许在我的网站上发表评论。这很好,但我想对它的工作方式做一些更改 但是,我不想直接在中对jquery注释进行更改,而是希望将它们放在不同的文件中,并尽可能使用我自己的函数扩展/修改注释对象 例如,我想更改名为createCommentingFieldElement的函数中发生的事情 我该怎么做?我就是这样解决的: 初始化jquery注释时,我可以使用如下函数对其进行扩展: $('#comments-container').comments({ getComments: functio
注释
对象
例如,我想更改名为createCommentingFieldElement
的函数中发生的事情
我该怎么做?我就是这样解决的: 初始化jquery注释时,我可以使用如下函数对其进行扩展:
$('#comments-container').comments({
getComments: function (success: any, error: any) {
var extensionMethods = {
doSomething: function () {
// this is my extended function.
// here you have the this object available.
}
}
};
$.extend(true, $('.jquery-comments').data('comments'), extensionMethods);
}
$('.jquery-comments').data('comments').doSomething();
您的新jquery注释扩展函数现在可以这样调用:
$('#comments-container').comments({
getComments: function (success: any, error: any) {
var extensionMethods = {
doSomething: function () {
// this is my extended function.
// here you have the this object available.
}
}
};
$.extend(true, $('.jquery-comments').data('comments'), extensionMethods);
}
$('.jquery-comments').data('comments').doSomething();