private WidgetBuilder init(String widgetClass, String widgetVar, String id) throws IOException {
        this.renderScriptBlock(id);

        // AJAX case: since jQuery 3 document ready ($(function() {})) are executed async
        //            this would mean that our oncomplete handlers are probably called before the scripts in the update nodes
        // or
        // we can also skip it when MOVE_SCRIPTS_TO_BOTTOM is enabled as the scripts are already executed when everything is ready
        if ((context.isPostback() && context.getPartialViewContext().isAjaxRequest()) || configuration.isMoveScriptsToBottom()) {
            this.init(widgetClass, widgetVar, id, false);
        }
        else {
            context.getResponseWriter().write("$(function(){");
            this.init(widgetClass, widgetVar, id, true);
        }

        return this;
    }
@param widgetClass   Constructor name of the widget
@param widgetVar     Name of the client side widget
@param id            Client id of the component
@param endFunction   If the init script is wrapped by a method and if the endFunction parentheses should be rendered.
@throws IOException if any IO exception occurs
@return              The current instance.
primefaces/src/main/java/org/primefaces/util/WidgetBuilder.java