如何扩展 jquery-评论?
How can I extend jquery-comments?
我正在使用 jquery-comments 允许在我的网站上发表评论。这工作正常,但我想对其工作方式进行一些更改。
但是,我不想直接在 jquery-comments.js 中更改 jquery-评论,而是想将它们放在不同的文件中,extend/modify [=11] =] 尽可能使用我自己的函数对象。
例如,我想更改名为 createCommentingFieldElement
的函数中发生的事情。
我该怎么做?
我是这样解决的:
当我初始化 jquery-comments 时,我可以用这样的函数扩展它:
$('#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 扩展函数现在可以这样调用:
$('.jquery-comments').data('comments').doSomething();
我正在使用 jquery-comments 允许在我的网站上发表评论。这工作正常,但我想对其工作方式进行一些更改。
但是,我不想直接在 jquery-comments.js 中更改 jquery-评论,而是想将它们放在不同的文件中,extend/modify [=11] =] 尽可能使用我自己的函数对象。
例如,我想更改名为 createCommentingFieldElement
的函数中发生的事情。
我该怎么做?
我是这样解决的:
当我初始化 jquery-comments 时,我可以用这样的函数扩展它:
$('#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 扩展函数现在可以这样调用:
$('.jquery-comments').data('comments').doSomething();