Javascript 下划线.js+;Visual Studio代码=未捕获的语法错误:意外标记{
我正在尝试在Visual Studio代码中使用下划线.js库。下划线是通过以下方式安装的:Javascript 下划线.js+;Visual Studio代码=未捕获的语法错误:意外标记{,javascript,visual-studio-code,underscore.js,Javascript,Visual Studio Code,Underscore.js,我正在尝试在Visual Studio代码中使用下划线.js库。下划线是通过以下方式安装的: npm install underscore 我的代码是: import {_} from "./node_modules/underscore/underscore.js"; var arr1 = [1, 2, 3]; var myFunction = function(element, index, list) { console.log(`Element : ${element}, Inde
npm install underscore
我的代码是:
import {_} from "./node_modules/underscore/underscore.js";
var arr1 = [1, 2, 3];
var myFunction = function(element, index, list) {
console.log(`Element : ${element}, Index : ${index}, Element found by index : ${list[index]}`);
_.each(arr1,myFunction);
Intellisense可以正确地显示所有内容,但当我调试时,我会
Uncaught SyntaxError: Unexpected token {
不知道我做错了什么。
Tnx以获取帮助。此语法
导入{{}
(ES模块样式)仅适用于节点中的新模块系统。从中导入的内容必须位于.mjs文件中
您可能可以通过执行(CommonJS样式)来做您想做的事情:
如果您不喜欢这样,请查看TypeScript或Webpack,或其他将填充ES模块语法的内容。函数的
}
在哪里?另外,请确保您的IDE设置为支持ES6,并且您的脚本是模块脚本。@Xufox}未被复制,抱歉。IDE已经设置好(我使用的是VS代码,目标是es6),但不确定将我的脚本设置为模块脚本意味着什么
const {_} = require("./node_modules/underscore/underscore.js");
var arr1 = [1, 2, 3];
var myFunction = function(element, index, list) {
console.log(`Element : ${element}, Index : ${index}, Element found by index : ${list[index]}`);
_.each(arr1,myFunction);