Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/423.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何扩展jquery注释?_Javascript_Jquery_Jquery Plugins - Fatal编程技术网

Javascript 如何扩展jquery注释?

Javascript 如何扩展jquery注释?,javascript,jquery,jquery-plugins,Javascript,Jquery,Jquery Plugins,我使用允许在我的网站上发表评论。这很好,但我想对它的工作方式做一些更改 但是,我不想直接在中对jquery注释进行更改,而是希望将它们放在不同的文件中,并尽可能使用我自己的函数扩展/修改注释对象 例如,我想更改名为createCommentingFieldElement的函数中发生的事情 我该怎么做?我就是这样解决的: 初始化jquery注释时,我可以使用如下函数对其进行扩展: $('#comments-container').comments({ getComments: functio

我使用允许在我的网站上发表评论。这很好,但我想对它的工作方式做一些更改

但是,我不想直接在中对jquery注释进行更改,而是希望将它们放在不同的文件中,并尽可能使用我自己的函数扩展/修改
注释
对象

例如,我想更改名为
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();