javascript - jQuery extending $.fn with an object? -



javascript - jQuery extending $.fn with an object? -

using difference between jquery.extend , jquery.fn.extend? there way have $('.selector').group.method(); , $('.selector').group.method2();

right have in main script

function forty() {}; var 40 = new forty(); (function(site) { $.extend(forty, { getbaseurl: function(extra) { = typeof !== 'undefined' ? : ''; homecoming forty.get('baseurl') + extra; }, get: function($what) { homecoming site[$what]; } }); })(site);

then later in file have:

$.extend(forty, { flyout: function() { $(this).on('click', function() { $('html').toggleclass('nav-open'); }); } });

and @ end have:

$.fn.extend({forty: forty});

right before have line:

$('.selector').forty.flyout();

so i'd $('.selector').forty.flyout();

is possible?

i managed solve this, going:

var 40 = {fn:{}}; $.fn.extend({forty: function() {return $.extend(this, forty.fn);}});

then assigning own functions so:

forty.fn.flyout = function() { $(this).on('click', function() { $('html').toggleclass('nav-open'); }); homecoming this; }

and using them like:

$('.js-toggle-nav').forty().flyout();

this seemed work epicly!

javascript jquery object

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -