• Jump To … +
    asm-llvm.js bcompile.js binterp.js browsercanvas.js bytecode-table.js canvastest.js ccanvas.js crender-styles.js crender.js ctiles.js events.js eventtests.js extensions.js global-es5.js global.js html-escape.js jcompile.js json2.js nodemain.js parse.js render.js render2.js require.js stdlib.js str-escape.js tdop.js tests.js text.js tiles.js tokenize.js top-level.js ts.js write-lua-bytecode.js write-lua-ops.js write-php-bytecode.js write-php-ops.js write-rust-bytecode.js write-rust-ops.js
  • global.js

  • ¶

    Some useful globals.

    Make a new object that inherits members from an existing object.

    if (typeof Object.create !== 'function') {
        Object.create = function (o) {
            function F() {}
            F.prototype = o;
            return new F();
        };
    }
  • ¶

    bind 'this' and optionally some other prefix parameters to a function.

    if (typeof Function.prototype.bind !== 'function') {
        Function.prototype.bind = function() {
                var method = this;
  • ¶

    avoid making a function wrapper if we don't have to

                if (arguments.length === 0) {
                    return method;
                }
                var nthis = arguments[0];
  • ¶

    avoid copying the arguments array if we don't have to

                if (arguments.length === 1) {
                    return function bind0 () {
                        return method.apply(nthis, arguments);
                    };
                }
  • ¶

    ok, we need to copy the bound arguments

                var nargs = [];
                var i = 1;
                while (i < arguments.length) {
                    nargs.push(arguments[i]);
                    i += 1;
                }
                return function bindN () {
  • ¶

    use concat.apply to finesse the fact that arguments isn't necessarily a 'real' array.

                    return method.apply(nthis, Array.prototype.concat.apply(
                                        nargs, arguments));
                };
        };
    }