Skip to content

Only load once example pattern #1

@frank-dspeed

Description

@frank-dspeed
blog = {};
blog.comments = blog.comments || {};
blog.comments.debugMode = false;

blog.isFirstLoad = function(namesp, jsFile) {
    var isFirst = namesp.firstLoad === undefined;
    namesp.firstLoad = false;
    
    if (!isFirst) {
        console.log(
            "Warning: Javascript file is included twice: " + 
                jsFile);
    }

    return isFirst;
};


$(document).ready(function () {
    if (!blog.isFirstLoad(blog.comments, "comments.js")) {
        return;
    }

    // normal event handling stuff.
    $("#nameIt").click(function(e) {
        var name= $("input[type=text]").val();    
        $("#nameOut")
            .append("<div>Hi there " + name + "</div>");
    });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions