I have seen 2 syntax for javascript prototype : first is from tutorial http://www.w3schools.com/js/js_object_prototypes.asp second is generated by typescript http://www.typescriptlang.org/Playground
What's the advantage of second syntax over first simpler and traditional constructor syntax ?
https://jsfiddle.net/v6gxe7wc/1/
function Person1(first, last) {
this.firstName = first;
this.lastName = last;
}
var Person2 = (function () {
function Person2(first, last) {
this.firstName = first;
this.lastName = last;
}
return Person2;
})();
var person1 = new Person1("John", "Doe");
var person2 = new Person2("John", "Doe");