javascript - Error - Don't make functions within a loop -


i trying replace placeholders in email template, following code:-

i getting error : don't make functions within loop

var dataplaceholders = [{             "username":"john johny",             "website":"w3schools . com"             }];  template_html = "<b>hello <%= username %>,</b><br/><br/> successfuly registered on xyz.<br/><br/>thank <%= website %>"; 

function call :-

function replaceplaceholders(dataplaceholders, template_html){     (var = 0; < dataplaceholders.length; i++) {         var obj = dataplaceholders[i];         template_html += "" + template_html.replace("/<%=%>/g", function (match, property) {             return obj[property];         }) + "";      }     return template_html; } 

thanks help.

from jslint error explanations:

the fundamental problem here javascript interpreter create instance of function per loop iteration. has because doesn't know if function object modified elsewhere. since functions standard javascript objects, can have properties other object, changed in loop. creating function in loop context, cause interpreter create multiple function instances, can cause unexpected behavior , performance problems.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -