RcBuilder@walla.com
call centre: 054-5614020

javascript instanceof

26
Jan
2016
Posted by: RcBuilder  /   Category: class / function / JAVASCRIPT / Object / prototype   /   No Comments

javascript instanceof

structure:

[instance] instanceof [type]

e.g: person instanceof Person

using:

function Person(Name) {
this.Name = Name;
}

function Employer(Name) {
this.Name = Name;
}

var person = new Person(‘Roby Cohen’);
var employer = new Employer(‘Roby Cohen’);

console.log(person instanceof Person); // true
console.log(employer instanceof Person); // false
console.log(employer instanceof Employer); // true

if (person instanceof Person)
console.log(‘PERSON : ‘ + person.Name); // PERSON : Roby Cohen

notice! any class inherit from object therefore both person and employer are also instance of Object
console.log(person instanceof Object); // true
console.log(employer instanceof Object); // true

var p1 = ‘some string’;
console.log(p1 instanceof Object); // false

Author Avatar

About the Author

בניית אתרים ופתרונות טכנולוגים | RcBuilder

No Comments


  • פיתוח מערכות
  • פתרונות טכנולוגים
  • קידום אתרים
  • בניית אתרים