www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] What is l in the code?

  1. #1
    Join Date
    May 2008
    Posts
    57

    resolved [RESOLVED] What is l in the code?

    I got a piece of code in a google chrome extension. There is "l" in the code but I don't understand it.
    Is it an object?
    Code:
    var b, l = l || {};
    l.global = this;
    l.exportPath_ = function (a, c, d) {
        a = a.split(".");
        d = d || l.global;
        a[0] in d || !d.execScript || d.execScript("var " + a[0]);
        for (var e; a.length && (e = a.shift());) a.length || void 0 === c ? d = d[e] ? d[e] : d[e] = {} : d[e] = c
    };
    l.define = function (a, c) {
        l.exportPath_(a, c)
    };
    l.DEBUG = !0;
    l.LOCALE = "en";
    l.TRUSTED_SITE = !0;
    l.provide = function (a) {
        l.exportPath_(a)
    };
    l.setTestOnly = function (a) {
        if (!l.DEBUG) throw a = a || "", Error("Importing test-only code into non-debug environment" + a ? ": " + a : ".");
    };
    l.getObjectByName = function (a) {
        a = a.split(".");
        for (var c = l.global, d; d = a.shift();)
            if (l.isDefAndNotNull(c[d])) c = c[d];
            else return null;
        return c
    };
    l.globalize = function (a, c) {
        var d = c || l.global,
            e;
        for (e in a) d[e] = a[e]
    };
    l.addDependency = function (a, c, d) {
        if (l.DEPENDENCIES_ENABLED) {
            var e;
            a = a.replace(/\\/g, "/");
            for (var f = l.dependencies_, g = 0; e = c[g]; g++) f.nameToPath[e] = a, a in f.pathToNames || (f.pathToNames[a] = {}), f.pathToNames[a][e] = !0;
            for (e = 0; c = d[e]; e++) a in f.requires || (f.requires[a] = {}), f.requires[a][c] = !0
        }
    };
    l.useStrictRequires = !1;
    l.ENABLE_DEBUG_LOADER = !0;
    l.require = function () {};
    l.basePath = "";
    l.nullFunction = function () {};
    l.identityFunction = function (a) {
        return a
    };
    l.abstractMethod = function () {
        throw Error("unimplemented abstract method");
    };
    l.addSingletonGetter = function (a) {
        a.getInstance = function () {
            if (a.instance_) return a.instance_;
            l.DEBUG && (l.instantiatedSingletons_[l.instantiatedSingletons_.length] = a);
            return a.instance_ = new a
        }
    };
    l.instantiatedSingletons_ = [];
    l.DEPENDENCIES_ENABLED = !1;
    l.DEPENDENCIES_ENABLED && (l.included_ = {}, l.dependencies_ = {
        pathToNames: {},
        nameToPath: {},
        requires: {},
        visited: {},
        written: {}
    }, l.inHtmlDocument_ = function () {
        var a = l.global.document;
        return "undefined" != typeof a && "write" in a
    }, l.findBasePath_ = function () {
        if (l.global.CLOSURE_BASE_PATH) l.basePath = l.global.CLOSURE_BASE_PATH;
        else if (l.inHtmlDocument_())
            for (var a = l.global.document.getElementsByTagName("script"), c = a.length - 1; 0 <= c; --c) {
                var d = a[c].src,
                    e = d.lastIndexOf("?"),
                    e = -1 == e ? d.length : e;
                if ("base.js" == d.substr(e -
                    7, 7)) {
                    l.basePath = d.substr(0, e - 7);
                    break
                }
            }
    }, l.importScript_ = function (a) {
        var c = l.global.CLOSURE_IMPORT_SCRIPT || l.writeScriptTag_;
        !l.dependencies_.written[a] && c(a) && (l.dependencies_.written[a] = !0)
    }, l.writeScriptTag_ = function (a) {
        if (l.inHtmlDocument_()) {
            var c = l.global.document;
            if ("complete" == c.readyState) {
                if (/\bdeps.js$/.test(a)) return !1;
                throw Error('Cannot write "' + a + '" after document load');
            }
            c.write('<script type="text/javascript" src="' + a + '">\x3c/script>');
            return !0
        }
        return !1
    }, l.writeScripts_ = function () {
        function a(f) {
            if (!(f in
                e.written)) {
                if (!(f in e.visited) && (e.visited[f] = !0, f in e.requires))
                    for (var h in e.requires[f])
                        if (!l.isProvided_(h))
                            if (h in e.nameToPath) a(e.nameToPath[h]);
                            else throw Error("Undefined nameToPath for " + h);
                f in d || (d[f] = !0, c.push(f))
            }
        }
        var c = [],
            d = {}, e = l.dependencies_,
            f;
        for (f in l.included_) e.written[f] || a(f);
        for (f = 0; f < c.length; f++)
            if (c[f]) l.importScript_(l.basePath + c[f]);
            else throw Error("Undefined script input");
    }, l.getPathFromDeps_ = function (a) {
        return a in l.dependencies_.nameToPath ? l.dependencies_.nameToPath[a] :
            null
    }, l.findBasePath_(), l.global.CLOSURE_NO_DEPS || l.importScript_(l.basePath + "deps.js"));
    l.typeOf = function (a) {
        var c = typeof a;
        if ("object" == c)
            if (a) {
                if (a instanceof Array) return "array";
                if (a instanceof Object) return c;
                var d = Object.prototype.toString.call(a);
                if ("[object Window]" == d) return "object";
                if ("[object Array]" == d || "number" == typeof a.length && "undefined" != typeof a.splice && "undefined" != typeof a.propertyIsEnumerable && !a.propertyIsEnumerable("splice")) return "array";
                if ("[object Function]" == d || "undefined" != typeof a.call && "undefined" != typeof a.propertyIsEnumerable && !a.propertyIsEnumerable("call")) return "function"
            } else return "null";
            else if ("function" == c && "undefined" == typeof a.call) return "object";
        return c
    };
    l.isDef = function (a) {
        return void 0 !== a
    };

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,709
    var b, l = l || {};

    l (lower case L) is l or an object {}
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. #3
    Join Date
    May 2008
    Posts
    57
    I don't know the meaning of
    Code:
    {}
    Global? Any link for that?

  4. #4
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    795
    {} is the shorthand version of creating an Object Literal. It's basically just an empty object as it is.

    In the original code:

    Code:
    var b, l = l || {};
    If l was previously declared, and its value was not falsey (undefined, null, false, 0, ""), then l will remain that value. OR (||), it will default to a blank object {}.
    JavaScript: Learn | Validate | Compact | bionoid

  5. #5
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,870
    {} is the short hand of new Object() as [] is short hand for new Array();

    As bionoid and vwphillips have explained, the purpose of
    Code:
    l=l || {};
    is also a short hand of...
    Code:
    l = typeof l == 'undefined' ? new Object() : l;
    or another longer way is...
    Code:
    if( typeof l == 'undefined' ){
        l = new Object();
    }
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.09100 seconds
  • Memory Usage 2,900KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (6)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (5)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (5)postbit
  • (5)postbit_onlinestatus
  • (5)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (70):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates