How to hide library source code in Google way?

前端 未结 2 703
失恋的感觉
失恋的感觉 2021-01-07 01:33

For instance, I have a library and I would like to protect the source code to being viewed. The first method that comes to mind is to create public wrappers for private func

2条回答
  •  孤街浪徒
    2021-01-07 02:21

    I don't know what google does, but you could do something like this (not tested! just an idea):

    function declarations:

    var myApp = {
      foo: function { /**/ },
      bar: function { /**/ }
    };
    

    and then, in another place, an anonymous function writes foo() and bar():

    (function(a) {
      a['\u0066\u006F\u006F'] = function(){
        // here code for foo
      };
      a['\u0062\u0061\u0072'] = function(){
        // here code for bar
      };
    })(myApp);
    

    You can pack or minify to obfuscate even more.

提交回复
热议问题