function Person(name) {
this.name = name;
return this;
}
var someone = new Person('someone');
console.log(someone.name);
var someoneelse = Person('someoneelse');
console.log(someoneelse.name);
It this a good pattern to implement constructor functions (classes). This works fine with both new and without new.
[Update:] I think I got the answer I was looking for. Using this without 'new' would return a global object and a very bad idea (Thanks to the comment by Vohuman "by Without using new, this in the constructor is the global object not an instance of the constructor")
[More Update:] Doing it the right way to take care of new and without new,
function Person(name) {
if (this instanceof Person) {
this.name = name;
}
else {
return new Person(name);
}
};