let pointConfig = [ { title: "Test", top: 45, left: 80, }, { title: "Test3", top: 125, left: 53, }, { title: "Test4", top: 85, left: 170, }, { title: "Test5", top: 115, left: 121, }, ]; let Point = ( function () { let Point = function ( conf, callback ) { this.config = conf; this.callback = callback; this.addSpecificCSS(); this.adHtml(); }; let proto = Point.prototype; proto.addSpecificCSS = function () { console.log( "Point addSpecificCSS" ); let css = ``; if ( $( "#point-css" ).length === 0 ) { $( "head" ).append( css.replace( / |\n/g, "" ) ); } }; proto.adHtml = function () { let container = $( "#point-container" ); let html = ``; for ( let conf of this.config ) { html += `
`; } container.append( html.replace( / |\n/g, "" ) ); this.callback( this ); }; proto.start = function () { let container = $( "#point-container" ); container.addClass( "start" ); }; return Point; }() ); $( document ).ready( () => { $( ".dropdown-trigger" ).dropdown(); let point; new Point( pointConfig, ( p ) => { point = p; point.start(); } ); } );