Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
Detect object literal being a serialization of a class

I am looking for a way to detect if an object literal is in fact a "non-instantiated" object of a certain class. I hope it will be more clear with an example:

class Range{
    from: number;
    to: number;

    constructor(from: number | Range, to?: number){

        if (from instanceof Range)
            Object.assign(this, from)
        else{
            this.from = from;
            this.to = to;
        }
    }

    average(){return (this.to -this.from) / 2;}
}


let one = new Range(1, 20)
let copyOfOne = structuredClone(one);   // This generates an object literal (or kind of ?), the method "average" is not in the prototype
let two = new Range(copyOfOne)          // Constructor won't detect the parmeter as instanceof Range

Is there a way to know if an object literal is in fact a "non-instantiated instance" of a certain class? (of course I could check if the object has the class properties, here is simple but with more complex objects would be impractical)

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!