我正在为JavaScript创建一个插件,我想为它添加可用的方法。 (例如if kwargs.get('x_is_date', False):
self.set_date_flag(True)
self.create_x_axis('xAxis',
format=kwargs.get('x_axis_format', '%d %b %Y'),
date=True)
self.set_custom_tooltip_flag(True)
else:
if kwargs.get('x_axis_format') == 'AM_PM':
self.x_axis_format = format = 'AM_PM'
else:
format = kwargs.get('x_axis_format', 'r')
self.create_x_axis('xAxis', format=format,
custom_format=kwargs.get('x_custom_format', False))
)我这样做的方式如下:
myPlugin.usefulMethod()
但是我看到很多插件都是这样创建他们的方法:
function MyPlugin(param1, param2) {
...
this.usefullMethod = function() {...};
this.anotherUserfullMethod = function(someParam) {...};
}
var plugin1 = new MyPlugin(someParam1, someParam2);
plugin1.usefullMethod();
哪种方法正确,为什么?它们之间的区别是什么?