www.webdeveloper.com
Results 1 to 5 of 5

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

  1. #1
    Join Date
    May 2008
    Posts
    55

    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,674
    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
    55
    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
    2,290
    {} 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();
    }
    Yes, I know I'm about as subtle as being hit by a bus..(\\.\ Aug08)
    Yep... I say it like I see it, even if it is like a baseball bat in the nutz... (\\.\ Aug08)
    I want to leave this world the same way I came into it, Screaming, Incontinent & No memory!
    I laughed that hard I burst my colostomy bag... (\\.\ May03)
    Life for some is like a car accident... Mine is like a motorway pile up...

    Problems with Vista? :: Getting Cryptic wid it. :: The 'C' word! :: Whois?

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



Recent Articles