How to check if a class has a specific property in JavaScript

1 Answer

0 votes
class Worker {
  constructor() {
    this.name = 'Tom';
  }
}
class Python extends Worker {
  constructor() {
    super();
    this.version = '3.8';
  }
}
 
const w1 = new Python();
 
document.write('name' in w1);
document.write('<br />');
document.write('version' in w1);
 
 
    
/*
run:
          
true
true
        
*/

 



answered Nov 5, 2019 by avibootz
edited Nov 6, 2019 by avibootz
...