JSFiddle - React, Tailwind, and code Playground

by Gene Arnold

JavaScript

function car(color,engine,callback){
			this.color = color;
			this.engine = engine;
			this.callback = callback;

			if(callback){
				callback();
			}
		}


		//It seems like the "this" in these callback functions are referring back to the window and not the car object.
    //This is what I seem to be having a problem with on my other project as well. How do I get the callback function
    //to know that "this" should be the car I'm currently looking at?
		var carOne = new car("red", "fast", function(){
			alert("I'm a " + this.color + " " + this.engine + " car");
		});


		var carTwo = new car("blue", "medium", function(){
			alert("I'm a " + this.color + " " + this.engine + " car");
		});

		var carThree = new car("green", "slow", function(){
			alert("I'm a " + this.color + " " + this.engine + " car");
		});