Comment

Comment by mythz

Have a look at the advanced compilation option: https://developers.google.com/closure/compiler/docs/api-tuto...

Basically when enabled it will rewrite normal property access, e.g: `myObj.foo` to something like `a.b` but wont shorten string literal access, e.g `myObj['foo']` just becomes `a.foo` which you would use for any API's you want to export.

For a real-world example I use string literals for declaring jquip's public API:

    p['removeAttr'] = function(name){
        return this['each'](function(){
          if (this.nodeType == 1) this.removeAttribute(name);
        });
    };
Which closure advanced rewrites to:

    q.removeAttr=function(a){return this.each(function(){this.removeAttribute(a)})};
Original: https://github.com/mythz/jquip/blob/master/dist/jquip.all.js

Compiled: https://github.com/mythz/jquip/blob/master/dist/jquip.all.cl...

parent mythz 11 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton