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

348
Views
Migración de Angularjs a Angular: prototipo de fábrica

Estoy migrando de angularjs a angular. Ya hice mucho, pero todavía estoy atascado con fábricas y prototipos. La carta representa una carta de juego.

 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); }

Ahora solo me pregunto cómo migrarlo, porque no hay más fábricas en angular. Estaba pensando en hacer que la función Tarjeta fuera una interfaz de tarjeta como en el tutorial angular https://angular.io/tutorial/toh-pt1 . ¿Crees que es una buena idea o me estoy perdiendo algo? Cualquier ayuda o idea sería apreciada!!!!

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

0

Puede usar una combinación de clase abstracta y constructor:

abstract class para obtener la funcionalidad del prototipo.

La lógica de configuración del valor inicial puede ir dentro del constructor . enlace de parque infantil

 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!