Tengo un área de entrada en mi HTML.
<input id="bookTitle" type="text">Ahora, mi javascript se ve así:
function Book(title){ this.title = title; } function addToLibrary(){ const title = document.querySelector("#bookTitle").value; const book = new Book(title) // replace the book variable name with the value of title }¿Cómo hago para que, en lugar de instanciar Book Class con libro variable, lo instancia con el valor del título en sí?
Por ejemplo,
Si mi entrada tiene el valor "Hobbit", quiero que Hobbit sea el nombre de la variable en lugar del libro.