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

This is just a style comment, but given JavaScript's open class prototypes and expando objects, I generally prefer to write these methods as new members on their natural classes. For example, the RegEx escape method would be on the RegEx class itself, rather than being a stand alone function.

Other than that, this is an incredibly useful set of functions that any JavaScript developer should have in their toolkit.



You mean like putting the methods into the native classes' prototypes? That's a bad idea. The reason why it is a bad idea is that you cannot extend a prototype only within a scope, i.e if you change the prototype, it'll be changed regardless of whether it'll break another library, or that another library replaces your methods and thus render your library broken. This opens up the risk that you'll end up with bugs that are hard to trace to their source.




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

Search: