Javascript Object Constructor Property

Description

Javascript Object Constructor Property

function Person( firstname, lastname, age ) {
        this.firstname = firstname;/*  w  w  w.  jav  a 2  s.  c o  m*/
        this.lastname = lastname;
        this.age = age;
}

let dave = new Person("Dave", "Smith", 28);

console.log( dave.constructor);

// we can create a new object from another object's constructor:
let mike = new dave.constructor("Mike", "Fox", 22);

// Is mike an instance of the Person object?
console.log( mike.constructor == Person );  // true



PreviousNext

Related