Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I obfuscate global variable using YUI without putting entire class inside a closure

Suppose there is a global variable which is a function

function MyClass(){}

and there are methods of this class such as

MyClass.func1 = function()
{
}

I want to ensure that YUI compression and obfuscation works without putting entire class inside a closure like

(function () {
    function MyClass(){}
    MyClass.func1 = function()
    {
    }
})();

Is there a way to make YUI compression work without doing this?

like image 973
gurvinder372 Avatar asked Apr 17 '15 13:04

gurvinder372


1 Answers

Well, I suppose you could wrap it in an anonymous function before compressing it, and then just remove the anonymous function after.

Also make sure you're using prototype ;)

(function () {
  function MyClass(){}
  MyClass.prototype.func1 = function()
  {
  }
})();

Results in:

(function(){function a(){}a.prototype.func1=function(){}})();

And just take out the anonymous function:

function a(){}a.prototype.func1=function(){}
like image 54
John Harding Avatar answered Oct 07 '22 08:10

John Harding