ho qualche JSON restituita al browser come questo "prodotto":Principiante JavaScript: Lavorare con JSON e oggetti in JavaScript
{ "Title": "School Bag", "Image": "/images/school-bag.jpg" }
voglio questi dati per essere un oggetto "Prodotto" in modo da poter usare prototipo metodi come un toHTMLImage()
che restituisce una rappresentazione HTML immagine del prodotto:
function Product() { }
Product.prototype.toHTMLImage = function() { //Returns something like <img src="<Image>" alt="<Title>" /> }
Come posso convertire i miei risultati JSON in un oggetto Product
in modo che posso usare toHTMLImage
?
Prova: stuff .__ proto__ = Product.prototype; –