// минус подхода - obj доступно только внутри этой функции }) ;(function($){ $.fn.functionName = function ( options ) { return this.each ( function () { new FunctionName ( this, options ); }); }; function FunctionName ( context, options ) { this.defaults = { // дефолтные значения }; $.extend ( true, this.defaults, options ); this.init ( context ); }
FunctionName.prototype = { init: function ( context, options ) { // что-то выполняем }, stop: function () { // что-то выполняем } } }(jQuery));
Есть еще вариант:
jQuery ( function () { jQuery ( '#obj' ).functionName ({ // свои значения, если отличны от дэфолтных })
// при каком-то событии нужно этот obj остановить
event = function () { // образно покажу событие document.getElementById ( 'obj' ).functionName.stop () // "достать" можно практичесски с любого места } // минусов пока не вижу, вот хочу узнать }) ;(function($){ $.fn.functionName = function ( options ) { return this.each ( function () { new FunctionName ( this, options ); }); }; function FunctionName ( context, options ) { this.defaults = { // дефолтные значения }; $.extend ( true, this.defaults, options ); this.init ( context ); }
FunctionName.prototype = { init: function ( context, options ) { context.FunctionName = this // присвоим этот объект самой ноде // что-то выполняем }, stop: function () { // что-то выполняем } } }(jQuery));
Какие негативные последствия обеих подходов, какой из них лучше?
You can post now and register later.
If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.
Актуальные контакты:
Telegram: @Nikker_web
E-Mail: tarasevich.email@gmail.com
Портфолио https://www.behance.net/d4d4186e
Разрабатываю дизайн групп в соц сетях, сайтов, приложений, другой дизайн под заказ
Актуальные контакты:
Telegram: @Nikker_web
E-Mail: tarasevich.email@gmail.com
Разрабатываю дизайн групп в соц сетях, сайтов, приложений, другой дизайн под заказ
Портфолио https://www.behance.net/d4d4186e
Question
mishka
Может название темы и не информативно, но лучше не придумал.
Пишу плагин на jQuery.
Использую такой подход:
Есть еще вариант:
Какие негативные последствия обеих подходов, какой из них лучше?
Есть ли что-то лучше?
Link to comment
Share on other sites
4 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.