UglifyJS-old icon indicating copy to clipboard operation
UglifyJS-old copied to clipboard

Added option for mangling privates in code gen (all members prefixed with a single underscore)

Open BonsaiDen opened this issue 13 years ago • 3 comments

Potentially unsafe, but was an easy add and I know a lot of people who want this, not only does it make the code even smaller (20% in my non-trivial use case) but it's also a nice to have feature if you want to make sure that nobody calls / accesses the stuff :)

Let me know what you think about it.

Best Ivo

BonsaiDen avatar Jan 27 '12 22:01 BonsaiDen

I do a lot of code with Google Analytics functions, and these functions all start with an underscore. And while I'd like to have this feature I can't use this because that would mangle these methods as well.

Maybe add an option to mangle double underscores only ?

eduardocereto avatar Feb 21 '12 08:02 eduardocereto

Some pitfalls in dbf2df3a45fbafaec7326eda060ee72dd7c8695e:

var foo = {}, bar = '_baz';
foo._baz = 42;
console.log('number' === typeof foo[bar]);
console.log(foo.hasOwnProperty('_baz'));
console.log(-1 !== Object.keys(foo).indexOf('_baz'));
with (foo) {
  console.log('number' === typeof _baz);
}

RGustBardon avatar Feb 29 '12 00:02 RGustBardon

Duplicate of issue #219.

RGustBardon avatar Feb 29 '12 02:02 RGustBardon