Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

    Rainbow["onHighlight"] = Rainbow.onHighlight;
Isn't that line useless since `obj['property'] == obj.property` is always true?

https://github.com/ccampbell/rainbow/blob/master/js/rainbow....



This is because I'm using Google Closure Compiler in advanced mode so all methods that do not get used get renamed.

In order to preserve the methods and keep them public you have to reference them like this.


This is what @export (and the related functions in the library for if you are not using annotations) are for. In the context of Closure, this is clumsy. But I expect that not all other minifiers offer the same flexibility.


No, it's not useless when it comes to advanced minimization when Rainbow.onHighlight might be minimized to Rainbox.a. By doing Rainbow['onHighlight'] ensures a method called onHighlight exists on the Rainbow object.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: