Constructor Can Return DIFFERENT Object?!

Constructors can LIE about what they create! If you return an object, it REPLACES the instance. The 'new' keyword becomes USELESS. instanceof returns false! This breaks OOP principles!

#javascript #javascripttricks #constructor #classsyntax #instanceof #javascriptweird #javascriptquiz #codingchallenge #javascriptshorts #javascriptwtf #oopquirks #advancedjavascript

https://www.youtube.com/watch?v=NSHaq1zbSWE

Constructor Can Return DIFFERENT Object?! #javascriptshorts

YouTube

Wer mit Java arbeitet, kennt den Operator instanceof wahrscheinlich schon länger. Er wird genutzt, um zu prüfen, ob ein Objekt einer bestimmten Klasse oder einem bestimmten Typ entspricht. Doch seit Java 16 gibt es eine deutliche Verbesserung: Pattern Matching für instanceof. Diese Neuerung sorgt

https://magicmarcy.de/pattern-matching-for-instanceof

#PatternMatching #instanceof #Java16 #Casting #Compiler #Negationen #Programming #Java

Pattern Matching for instanceof | magicmarcy.de

Wer mit Java arbeitet, kennt den Operator instanceof wahrscheinlich schon länger. Er wird genutzt, um zu prüfen, ob ein Objekt einer bestimmten Klasse oder einem bestimmten Typ entspricht. Doch seit Java 16 gibt es eine deutliche Verbesserung: Pattern Matching für instanceof. Diese Neuerung sorgt nicht nur für kompakteren Code, sondern macht ihn auch sicherer und besser lesbar – besonders für Einsteiger ist das ein echter Gewinn.

magicmarcy.de

Wer mit Java arbeitet, kennt den Operator instanceof wahrscheinlich schon länger. Er wird genutzt, um zu prüfen, ob ein Objekt einer bestimmten Klasse oder einem bestimmten Typ entspricht. Doch seit Java 16 gibt es eine deutliche Verbesserung: Pattern Matching für instanceof. Diese Neuerung sorgt

https://magicmarcy.de/pattern-matching-for-instanceof

#PatternMatching #instanceof #Java16 #Casting #Compiler #Negationen #Programming #Java

Pattern Matching for instanceof | magicmarcy.de

Wer mit Java arbeitet, kennt den Operator instanceof wahrscheinlich schon länger. Er wird genutzt, um zu prüfen, ob ein Objekt einer bestimmten Klasse oder einem bestimmten Typ entspricht. Doch seit Java 16 gibt es eine deutliche Verbesserung: Pattern Matching für instanceof. Diese Neuerung sorgt nicht nur für kompakteren Code, sondern macht ihn auch sicherer und besser lesbar – besonders für Einsteiger ist das ein echter Gewinn.

magicmarcy.de

TypeScript nicety. A variable's type is a union of classes:

declare const aorb: A | B

You want to handle each class separately with a sequence like

if (aorb instanceof A) { }
else if (aorb instanceof B) { }

You also want to be sure that if another class is added you don't forget to amend the if-cascade. Just add:

else { throw aorb satisfies never; }

Full code on playground. Can this be done with switch too?

https://www.typescriptlang.org/play/?#code/MYGwhgzhAEBCkFMA8AVaCAeAXBA7AJjPBMigHxnQDeAvgFCiQwCC62ehciSzlVd0QdABOCMPgD2uEAE9oYaAF5oAImYqA3HXqMocNjgJFusPgKGjxU2dABGS1bE3aG4PQGEDHYySTuzQiJiktJywA4q7s70dAD0sdDM+PjQujCeWBLyEsL2YATQJAjQABYSAO7QWCXFwBIAtgAOAJYgCMKpDY3gzbgwYLYSAK5YcQnVxb11TW040CDNEFjQEgBm0M2rABS9S-nACGsAlKmI-csT0AAGEGBYi6vNCBBXAHR0+AiMop19y2A5WwALkS0AAPnAtJtoFsAbkNn99od1swTvxAnU+hI2q8QBIAOZbFRw+wlSCqaAAamyuVeYCOWho6BAJA22xJCL2uAOazgaPMgkxEGxCFxBKJHLJMBUVJptletiO2mZrPRQmqwgqcsKdweTxguAQADd2oy6EA

#TypeScript #exhaustivenesstest #instanceof #exhaustive

TS Playground - An online editor for exploring TypeScript and JavaScript

The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.