when I define "Car" like below,
var Car = function(m) {
var model = m;
function getModel() {
return model;
}
return {
getModel : getModel
}
};
and I created an object like this var c1 = new Car("qwer");
in this case, I can't access to model directly, only by closure.
(console.log(c1.model); => undefined)
(console.log (c1.getModel ()); => qwer)
but when I define "Car" like below,
var Car = function(m) {
var model = m;
function getModel() {
return this.model;
}
return {
getModel : getModel
}
};
and I created object var c2 = new Car("asdg");
in this case, I can not access to model directly , but also by closure.
(console.log(c2.model) => undefined)
(console.log (c2.getModel () => undefined)
can u tell me why this happens?