I was working with JavaScript for quite some time till I stumbled upon a simple problem. The question was: How can I extend default JavaScript objects? I'm quite surprised this problem didn't show up earlier, but anyway, I had to face it recently. I knew that objects can be prototyped, just never did it myself till then. My concrete problem was, that I wanted to add a simple addClass and removeClass method. I was certain that I can find many ready solutions, but I wanted to do it myself. So I started to search the web and get myself deep into this problem. I was able to create those methods I mentioned above, but there was one problem. What a surprise, the problem was Internet Explorer. So I looked this problem up and find out, that IE Object prototypes are read only. I looked for a workaround and I got some results, but there were some problems. First I describe a concrete solution I found. I found HTMLElement.htc on the internet, that extended Objects for IE, so they could be prototyped. I won't share this solution because it had 2 strong problems:
1, The first was, it was really very slow, unacceptable, it ran through all elements on page and even for not very complex page it took a time in seconds, close to 10 seconds.
2, Second problem, even worse was, that dynamically created elements weren't prototyped.
About prototyping, there are certain facts you should know. There are some strong arguments, that are not hard to find on the internet, which tells you that prototyping might not be the best solution. However I was in position where prototyping could really help me a lot, but not with the mentioned methods. I left HTMLElement prototyping behind, I found much more ellegant solution to that. If you want to know more about that, check this article.
However I wanted to use prototyping on for example JavaScript String objects, which was really easy and there were no problems with implementation even in IE. Of course there is one very sad thing, you can't change String itself with prototypes. To end this article I will provide one link, which helped me very much in the beginning of my JavaScript Object prototyping tour, here it is:
http://phrogz.net/js/Classes/ExtendingJavaScriptObjectsAndClasses.html