Can someone tell me what is difference between:
function Customer(name, age) {
this.Name = name;
this.Age = age;
}
var cust1 = new Customer('Your Name', 20);
var name1 = cust1.Name;
var age1 = cust1.Age;
and:
function Customer() {
return {
Name: 'Your Name',
Age: 20
}
};
var cust2 = Customer();
var name2 = cust2.Name;
var age2 = cust2.Age;
It produces the same output, after all, but the mechanics are different and I am not sure why.
what's the purpose of "new" in the first one though i could just do this:
var cust1 = Customer('Your Name', 20);
var name1 = cust1.Name;
var age1 = cust1.Age;