On this simple trick, I'll show the difference between operators in
and hasOwnProperty
.
class Validator {
static isValid() {
return true;
}
}
class EmailValidator extends Validator {
static checkEmail(email) {
return true;
}
}
console.log('isValid' in EmailValidator); // => true
console.log(EmailValidator.hasOwnProperty('isValid')); // => false
The operator "in":
It enables us to check inheritance keys like in the example above.
The operator "hasOwnProperty":
It only returns true if the object that property directly and not from parents.
Did you like it? Comment, share! β¨
Top comments (0)