Here is the simple javascript constructor pattern, in the first look it looks good and of-course it works fine.
The issue in this piece of code is toString() method. The toString() will be redefined for each new objects. Ideally every method should be shared by every instance of Person.
The solution using prototype
Here is the simple work around to get rid of this.
This prototype method will save memory since it uses the same object of toString method with all the instances of Person. Using `this` results each instance having independent copy of function toString.
Pingback: PHPRepo » Javascript : constructor pattern