Coming at an answer more as a programmer than a UI person, in a lot of cases, if you have the luxury to do so, it is very often a good idea to throw any prototype away once you get to a certain point and – not so much "start from scratch" – but start a re-implementation now that you know where you want to end up.
The final prototype is likely to have been built iteratively; even if it is now (roughly) where you want it to be, the route it took to get there might mean its implementation isn't really "right".
If the prototype is essentially "static" HTML, trying to retrofit dynamic creation (assuming that this is needed) may be messier than starting the process of dynamic creation from a clean(ish) slate (but using the static HTML as a known destination).
If the prototype is being created dynamically, again the history of how the prototype was created may mean that the current way of creating the HTML isn't the best way of doing so.
In a lot of cases, you can by all means lift elements of the prototype into the re-implementation, but doing that – rather than trying to turn the prototype into a "finished product" – can often result in better code.
Obviously, you often won't get the time needed to do all this, and you have to just "harden" the prototype... but while I don't think I've ever regretted re-implementing a prototype when we've been allowed to do so, there have been many cases where we weren't allowed to and six months to a year later I really wish we had.