gpt4 book ai didi

javascript - 无法理解为什么 JS Code 没有在 JS Bin 中运行

转载 作者:行者123 更新时间:2023-12-02 21:19:37 25 4
gpt4 key购买 nike

当我尝试运行以下代码时,在 JS Bin 中收到以下错误代码,我做错了什么吗?

let myTodos = {
day: "Monday",
meetings: 0,
meetDone: 0,
}

let addMeeting = function(todo, meet = 0) {
todo.meetings = todo.meetings + meet;
}


let meetDone = function (todo, meet = 0) {
todo.meetDone = todo.meetDone - meet;

}

let resetDay = function (todo) {
todo.meetings = 0;
todo.meetDone = 0;
}

let getSummaryOfDay = function (todo) {
let meetleft = todo.meetings + todo.meetDone;
return `You have ${meetleft} meetings for today.!`;
}

addMeeting(myTodos, 4);
addMeeting(myTodos, 2);
meetDone(myTodos, 5);
console.log(getSummaryOfDay(myTodos));
console.log (myTodos);

我在 JS Bin 中遇到的错误如下。

"error"
"SyntaxError: Unexpected token '{'
at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:13924
at https://static.jsbin.com/js/prod/runner-4.1.7.min.js:1:10866"

最佳答案

This is a bug in JSBin's loop protection.

当您使用此代码 ( JSBin link ) 时:

let myTodos = {
day: "Monday",
meetings: 0,
meetDone: 0,
}

let addMeeting = function(todo, meet = 0) {
todo.meetings = todo.meetings + meet;
}


let meetDone = function (todo, meet = 0) {
todo.meetDone = todo.meetDone - meet;

}

let resetDay = function (todo) {
todo.meetings = 0;
todo.meetDone = 0;
}

let getSummaryOfDay = function (todo) {
let meetleft = todo.meetings + todo.meetDone;
return `You have ${meetleft} meetings for today.!`;
}

addMeeting(myTodos, 4);
addMeeting(myTodos, 2);
meetDone(myTodos, 5);
console.log(getSummaryOfDay(myTodos));
console.log (myTodos);

JSBin 生成以下将被执行的文档:

<!DOCTYPE html>

<html>
<head>
<meta charset=\"utf-8\">
<meta name=\"viewport\" content=\"width=device-width\">
<title>JS Bin</title>
<style id=\"jsbin-css\">

</style>
</head>
<body>

<script>try {let myTodos = {
day: \"Monday\",
meetings: 0,
meetDone: 0,
}

let addMeeting = function(todo, meet = 0) {
todo.meetings = todo.meetings + meet;
}

let meetDone = function (todo, meet = 0) {
todo.meetDone = todo.meetDone - meet;

}

let resetDay = function (todo) {
todo.meetings = 0;
todo.meetDone = 0;
}

let getSummaryOfDay = function (todo) {
let meetleft = todo.meetings + todo.meetDone;
{
if (window.runnerWindow.protect.prote{;window.runnerWindow.protect.protect({ line: 23, reset: true }); ct({ line: 23 })) break;
return `You have ${meetleft} meetings for today.!`;
}}

}

addMeeting(myTodos, 4);
addMeeting(myTodos, 2);
meetDone(myTodos, 5);
window.runnerWindow.proxyConsole.log(getSummaryOfDay(myTodos));
window.runnerWindow.proxyConsole.log (myTodos);
} catch (error) { throw error; }

//# sourceURL=xibavicide.js
</script>
</body>
</html>

请注意模板文字是如何包装在保护代码中的,现在它在语法上不正确。

据推测,保护是为了阻止无限循环。

如果您只是删除 for ( JSBin link ),则不会触发保护,并且生成的文档在语法上是正确的:

<!DOCTYPE html>

<html>
<head>
<meta charset=\"utf-8\">
<meta name=\"viewport\" content=\"width=device-width\">
<title>JS Bin</title>
<style id=\"jsbin-css\">

</style>
</head>
<body>

<script>try {let myTodos = {
day: \"Monday\",
meetings: 0,
meetDone: 0,
}

let addMeeting = function(todo, meet = 0) {
todo.meetings = todo.meetings + meet;
}

let meetDone = function (todo, meet = 0) {
todo.meetDone = todo.meetDone - meet;

}

let resetDay = function (todo) {
todo.meetings = 0;
todo.meetDone = 0;
}

let getSummaryOfDay = function (todo) {
let meetleft = todo.meetings + todo.meetDone;
return `You have ${meetleft} meetings today.!`;
}

addMeeting(myTodos, 4);
addMeeting(myTodos, 2);
meetDone(myTodos, 5);
window.runnerWindow.proxyConsole.log(getSummaryOfDay(myTodos));
window.runnerWindow.proxyConsole.log (myTodos);
} catch (error) { throw error; }

//# sourceURL=roqosiyasa.js
</script>
</body>
</html>

您可以使用错误中建议的解决方法 - 在 JavaScript 区域的任何位置添加 //noprotect 注释将阻止循环保护触发。 JSBin link

关于javascript - 无法理解为什么 JS Code 没有在 JS Bin 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60882724/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com