JavaScript Overload Patterns
Update I have continued with patterns into JavaScript Override Patterns . We all know JavaScript does not implement a native methods overload concept and what we usually do on daily basis is to emulate somehow this Classic OOP behavior. There are several ways to do it, all of them with pros and cons, but what is the best way to implement it? A common situation Let's imagine we would like to have a method able to accept different arguments types and return something accordingly with what we received. Usually in Classic OOP an overload cannot redefine the returned type but in JavaScript we can do " whatever we want ", trying to be still consistent, so that we can consider us more lucky than C# or Java guys, as more flexible as well. For this post, the behavior we would like to obtain will be similar to the one we can find in jQuery library, one of the most used, famous, and friendly libraries I know. // create an instance var me = new Person(); // set some property // vi...