简体   繁体   English

在闭包中覆盖私有函数

[英]Overriding a private function within a closure

I have this puzzler. 我有这个难题。 I've downloaded a jQuery plugin that has the following construction 我已经下载了具有以下结构的jQuery插件

(function($, undefined) {
 function a() {
  ...
 }

 $.fn.fullCalendar = function(options) {
  ...
  var avar = a(); 
  ...
 }
})(jQuery);

and my taks is to modify the plugin (I need to override the 'a' function) but I can't touch the core and I need to modify it from an external file. 我的任务是修改插件(我需要重写'a'函数),但我无法触及内核,需要从外部文件进行修改。 So... the problem is I don't know is there at all a way to access an unnamed closure and the second if I'd be able to will I be able to override a private function within it? 所以...问题是我不知道有没有办法访问未命名的闭包,如果可以的话,我可以覆盖其中的私有函数吗?

To be more specific: the plugin is: http://arshaw.com/fullcalendar and I need to override the 'daySegHTML' function within the core. 更具体地说:插件是: http ://arshaw.com/fullcalendar,我需要在内核中覆盖“ daySegHTML”功能。

Thank You for any advices. 谢谢您的任何建议。

You can't override functions in closures (at least not if they aren't exposed to the outside somehow). 您不能覆盖闭包中的函数(至少如果不以某种方式暴露于外部则不能如此)。 The only chance to modify it, is modifying the source code itself (if it's license allows it). 修改它的唯一机会是修改源代码本身(如果许可证允许的话)。

Closures are used to "hide" functionality from the user. 闭包用于向用户“隐藏”功能。 It is probably the only reason why there are powerful javascript libraries like google maps out there. 这可能是为什么有强大的JavaScript库(例如Google Maps)在那里的唯一原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM