如何在 jQuery 中扩展现有的对象方法?
例如,我正在使用jqBarGraph。现在我想给addGrid()它添加一个函数。我在想我会这样做:
(function($) {
$.fn.jqBarGraph.addGrid = function(){
var o = this;
// do something with 'o'
return o;
}
})(jQuery);
...但是当我打电话时$('#chart').jqBarGraph(options).addGrid();——我得到了错误:
Uncaught TypeError: Cannot call method 'addGrid' of undefined