I would like to do the following in JavaScript:
var myObject.name = myString;
function newFunction(){myObject.name}
Is it possible to use a string as the contents of a function? How would you convert it to be usable?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I believe you want
myStringto hold code, right ?You can execute that code by using the
eval()MDN docs method.Warning !
be sure to read the Don’t use eval! section though ..