hello,
I learned in the last lesson about private Properties inside the function constructor.
what i don’t understand is, how can i access or use functions with methods?
when i try to create a new instance of this constructor function, i get undefined. here is what i tried:
//this is the constructor:
var Car = function() {
// this is a private variable
var speed = 10;
// these are public methods
this.accelerate = function(change) {
speed += change;
};
this.decelerate = function() {
speed -= 5;
};
this.getSpeed = function() {
return speed;
};
};
var suburu = new Car();
console.log(suburu.accelerate(5)); // returns undefined