When I create a new object from a function, using the new
operator, I get an object whose properties I can access.
However, if I return a function from the constructor, the object has no properties and returns undefined when I try to access them. Why?
function Car1() {
this.brand = "Honda"
}
var car1 = new Car1()
console.log(car1.brand) // "Honda"
function Car2() {
this.brand = "Honda"
return function() {
console.log('TEST');
}
}
var car2 = new Car2()
console.log(car2.brand) // undefined. why??