I am reading Javascript for Kids by Nick Morgan as a beginner, and I produced the following JavaScript code -
var Car = function(x,y) {
this.x = x;
this.y = y;
}
Car.prototype.draw = function () {
var carHtml = '<img src="http://nostarch.com/images/car.png">';
this.carElement = $(carHtml);
this.carElement.css({
position:"absolute",
left:this.x,
top:this.y
});
}
var tesla = new Car (20,20);
var nissan = new Car (100,200);
tesla.draw();
nissan.draw();
Now, I used the JavaScript constructor method to create objects and prototypes
technique to create the draw method, which I can call on the car objects I have created from each instance of car
.
From my experience in Python, all methods can access all the properties of an object created from an instance of a class.
My question is, are properties accessible by all methods in an object created by the car constructor?