March 8, 2001 - Finding an Object's Superclass | WebReference

March 8, 2001 - Finding an Object's Superclass

Yehuda Shiran March 8, 2001
Finding an Object's Superclass
Tips: March 2001

Yehuda Shiran, Ph.D.
Doc JavaScript

You can probe the superclass of any object via its constructor property. This property returns the function by which the object was created with the new operator. All objects (both native and user-defined) inherit from the Object object. Since the Object object supports the constructor property, all objects supports it as well. Let's look at the Employee object:

function Employee() {
  this.dept = "HR";
  this.manager = "John Johnson";
}
function printProp() {
  var Ken = new Employee();
  alert(Ken.constructor);
}

When you ask for the constructor property, you should get a listing of the Employee function: