Is it a right way in typescript to detect that two object instantiated from similar class without instanceof operator?
abstract class CommonText {}
class BoldText {} extends CommonText
class ItalicText {} extends CommonText
const someBoldText = new BoldText("I like");
const anotherBoldText = new BoldText("cookies");
const italicText = new ItalicText("cursive");
//Comparison
if(someBoldText.constructor === anotherBoldText.constructor) {
// Run operation
}
if(someBoldText.constructor === italicText.constructor) {
// Should not be executed
}
It works fine but it`s a little bit ugly and I feel that there is a better way to do this.
Subquestion: Could you please explain me what exactly is compared in this case? Is it a pointers? Or signatures?
I am trying to create WYSIWYG editor using typescript and Vue.js as project to learn typescript. General idea is to recreate common browser behaviour with custom handlers. I have stoped on text styling and all works good, but there is a problem with data optimistaion which concludes in siblings which have the same style. For example: Scheme. So, when two object have same styling they should be merged into one.