Just a string. Add \\\' to it every time there is a single quote.
replace works for the first quote, so you need a tiny regular expression:
replace
str = str.replace(/'/g, "\\'");