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

344
Views
Angularjs to Angular Migration: factory prototype

I am migrating from angularjs to angular. I already did a lot, but I am still stuck with factories and prototypes. Card represents a play card.


        function Card() {
            this.remoteId = 0;
            this.version = 0;
            this.name = "";
            this.stars = 0;
        }

       Card.prototype = {
            getFromRemote: getFromRemote,
            initFromRemote: initFromRemote,
            updateFromCard: updateFromCard,
            createImage: createImage,
           };


      return (Card);
     }

Now I am just wondering hhow to migrate it, because there are no more factories in angular. I was thinking about making the Card function a card interface like in the angular tutorial https://angular.io/tutorial/toh-pt1. Do you think that is a good idea or do I miss something? Any help or ideas would be appreciated!!!!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use a combination of abstract class and constructor:

abstract class to get functionality of prototype.

Initial value setting logic can go inside the constructor. playgrond-link

 abstract class AbsCard {

  abstract remoteId: number;
  abstract version: number;
  abstract name: string
  abstract stars: number;

  public initFromRemote(): void {
    this.remoteId = 0;
  }

  public print() {
    console.log(this);
  }

}

class Card extends AbsCard {

  public remoteId: number = 0;
  version: number = 0;
  name: string = '';
  stars: number = 0;
  
  public constructor() { 
    super();
    /* other creation logic can come here */
  }
}

let c = new Card();
c.print();
about 4 years ago · Juan Pablo Isaza Report
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!