我在Firefox 47.0.1中使用Firefox检查器在控制台中尝试此代码。我在最后一个eval语句中收到错误:
eval( 'jspaginate["init"] =' + newCode);
我发誓最后一个评估工作在2016年8月左右!我收到此错误
SyntaxError:missing;在陈述之前
这是我的代码。我发现前两个eval语句有效。
var debug = 1;
newCode = `init: function(target, current){
console.log (" update:");
this.data.pageIndex = current;
this.pushState(target, current);
this.getData(target);
}`;
console.log ("newCode typeof is " + typeof newCode + " -->" + newCode+"<--");
var passString = new String('jspaginate["init"] =' + newCode);
console.log ("passString -->" + passString + "<--");
eval(passString);
if ( debug ) console.log("--> update:\n"+window.jspaginate["init"].toString() );
eval( new String('jspaginate["init"] =' + newCode));
if ( debug ) console.log("--> update:\n"+window.jspaginate["init"].toString() );
console.log ("constant typeofis " + typeof ('jspaginate["init"] =' + newCode) );
/* This eval gets an error */
eval( 'jspaginate["init"] =' + newCode);
console.log ("second eval completed." );
if ( debug ) console.log("--> update:\n"+window.jspaginate["init"].toString() );
这是我在控制台中看到的内容。我将代码粘贴到控制台中,然后按Enter键。我在这个页面上 https://discussions.apple.com/thread/7824331
var debug = 1;
newCode = `init: function(target, current){
console.log (" update:");
this.data.pageIndex = current;
this.pushState(target, current);
this.getData(target);
}`;
console.log ("newCode typeof is " + typeof newCode + " -->" + newCode+"<--");
var passString = new String('jspaginate["init"] =' + newCode);
console.log ("passString -->" + passString + "<--");
eval(passString);
if ( debug ) console.log("--> update:\n"+window.jspaginate["init"].toString() );
eval( new String('jspaginate["init"] =' + newCode));
if ( debug ) console.log("--> update:\n"+window.jspaginate["init"].toString() );
console.log ("constant typeofis " + typeof ('jspaginate["init"] =' + newCode) );
/* This eval gets an error */
eval( 'jspaginate["init"] =' + newCode);
console.log ("second eval completed." );
if ( debug ) console.log("--> update:\n"+window.jspaginate["init"].toString() );
newCode typeof is string -->init: function(target, current){
console.log (" update:");
this.data.pageIndex = current;
this.pushState(target, current);
this.getData(target);
}<--
passString -->jspaginate["init"] =init: function(target, current){
console.log (" update:");
this.data.pageIndex = current;
this.pushState(target, current);
this.getData(target);
}<--
--> update:
function (action, last){
var view = this,
target, current;
if(this.loading !== true){
view.loadingSequence();
window.paginationActive = true;
if(action === 'first'){
target = 0;
view.update(target, 0);
}else if(action === 'prev'){
current = parseInt(view.data.pageIndex)-1;
target = (current)*view.data.range;
view.update(target, current);
}else if(action === 'next'){
current = parseInt(view.data.pageIndex)+1;
target = (current)*view.data.range;
view.update(target, current);
}else if(action === 'last'){
current = parseInt(last)-1;
target = (current)*view.data.range;
view.update(target, current);
}
}
}
--> update:
function (action, last){
var view = this,
target, current;
if(this.loading !== true){
view.loadingSequence();
window.paginationActive = true;
if(action === 'first'){
target = 0;
view.update(target, 0);
}else if(action === 'prev'){
current = parseInt(view.data.pageIndex)-1;
target = (current)*view.data.range;
view.update(target, current);
}else if(action === 'next'){
current = parseInt(view.data.pageIndex)+1;
target = (current)*view.data.range;
view.update(target, current);
}else if(action === 'last'){
current = parseInt(last)-1;
target = (current)*view.data.range;
view.update(target, current);
}
}
}
constant typeofis string
SyntaxError: missing ; before statement