Передача параметров в плагин и namespacing
Столкнулся с такой проблемой.
Есть начальный код плагина ;(function($, window, document, undefined){ var text = '', methods = { init: function(text, options){ options = $.extend({}, $.fn.myPlugin.defaultOptions, options); console.log(text); return this; } } $.fn.myPlugin = function(text, method){ if (text != '') { // Тут беда return methods['init'].apply(this, Array.prototype.slice.call(arguments, 1)); } else { if (methods[method]) { return methods[method].apply(this, Array.prototype.slice.call(arguments, 1)); } else if (typeof method === 'object' || ! method) { return methods.init.apply(this, arguments); } else { $.error('Method ' + method + ' does not exist!'); } } } $.fn.myPlugin.defaultOptions = { param1: false } })(jQuery, window, document); И вызов $('body').myPlugin('foo', 'options': { param1: true }); В консоли получаю Код:
missing ) after argument list |
Так параметры в функции на javascript непередают.
myPlugin('foo', 'options': { //ошибка param1: true }); обычно просто myPlugin('foo', { param1: true }); ну а если всё же очень хочется передать имя передаваемого параметра то myPlugin('foo', {'options':{ param1: true }}); |
Спасибо, уже разобрался.
|
Часовой пояс GMT +3, время: 16:33. |