Testing if something is a class in javascript

There is really no such thing as a “class” in javascript — everything but primitives are an object. Even functions are objects.

instanceof DOES work with functions though. Check out this link.

function Car(make, model, year)
{
  this.make = make;
  this.model = model;
  this.year = year;
}
var mycar = new Car("Honda", "Accord", 1998);
var a = mycar instanceof Car;    // returns true
var b = mycar instanceof Object; // returns true

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)