Prevent Uglifyjs From Renaming Certain Functions
I have a function that has a constructor within it. It creates a new object and returns it: function car() { function Car() {} return new Car(); } As a result uglify renames
Solution 1:
You need to use the reserved-names
parameter:
--reserved-names “Car”
Solution 2:
Even if you follow Bill's suggestion, there's still a problem with your approach.
car().constructor !== car().constructor
One would expect those to be equal
I would change your approach to creating a constructor and giving it a Factory constructor
/** @private */functionCar() {
...
}
Car.create = function() {
returnnew Car();
}
Or the following (module pattern), combined with Bill's approach. Then you're not returning an object with a different prototype every time
var car = (function() {
functionCar() {...}
returnfunction() {
returnnewCar();
}
})();
// car().constructor === car().constructor // true
Post a Comment for "Prevent Uglifyjs From Renaming Certain Functions"