I'm building a class that is shared between a game engine and an editor. There are some properties and methods I want to be defined in the editor, but not the engine so I wrote the following code
class Asset{
constructor(){
this.prop1 = 1;
}
}
if (window.IS_EDITOR){
Asset.prototype.editorProp = 2;
}
class Room extends Asset{
constructor(){
super();
this.prop2 = 3;
console.log(this)
//expected: {prop1: 1, prop2: 3, editorProp: 2}
//what I get: {pro1: 1, prop2: 3}
}
}
I'm basically just trying to conditionally add another property to the constructor, but I'm confused why the editorProp isn't showing up when I access this.
editorPropis on the prototype, as you’ve specified. You’re logging the instance instead. Just go through the prototype chain in your console and you’ll find this property.static setEditorProp(value) { this.editorProp = value; }(wherethisin static context is the class itself) and a getterget editorProp() { return Asset.editorProp; }?