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
Post a Comment