Skip to content

Instantly share code, notes, and snippets.

@rohozhnikoff
Last active December 24, 2015 17:19
Show Gist options
  • Save rohozhnikoff/6834561 to your computer and use it in GitHub Desktop.
Save rohozhnikoff/6834561 to your computer and use it in GitHub Desktop.
simple helper to create jquery-plugins, based on class-instance (just for concept)
function cloneStructuresPrimitives(input) {
// need checks on primitivesTypes, return input
return JSON.parse(JSON.stringify(input));
}
export default function(name, WidgetClass) {
return $.fn[name] = function(opt){
if (this.length > 0) return
baseOpt = opt || {};
this.each(function(){
instanceStates = $.extend(cloneStructuresPrimitives(baseOpt), {el: this})
new WidgetClass(instanceStates);
});
return this;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment