Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

349
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda