Hi - can anyone explain to me what is the difference between the two codes below in relation to how the 'friend' variable is assigned, more specifically I am trying to understand what exactly 'new' does behind the scenes, apart from the obvious answer that it creates an object :

Code:
function Person(name, age, job){
var o = new Object();
o.name = name;
o.age = age;
o.job = job;
o.sayName = function(){
alert(this.name);
};
return o;
}

var friend = new Person(“Nicholas”, 29, “Software Engineer”);
friend.sayName(); //”Nicholas”
Code:
function Person(name, age, job){
//create the object to return
var o = new Object();
//optional: define private variables/functions here
//attach methods
o.sayName = function(){
alert(name);
};
//return the object
return o;
}

var friend = Person(“Nicholas”, 29, “Software Engineer”);
friend.sayName(); //”Nicholas”