jjzjj

non-const

全部标签

javascript - const 已经在 ES6 开关 block 中声明

这个问题在这里已经有了答案:ErrorDuplicateConstDeclarationinSwitchCaseStatement(6个答案)关闭3年前。考虑文件sample.es6switch(1){case1:constfoo=1;break;case2:constfoo=2;break;}如果我用Node运行它,我得到了$node--versionv4.2.11$nodesample.es6/tmp/sample.es6:6constfoo=2;^SyntaxError:Identifier'foo'hasalreadybeendeclaredatObject.(/tmp/sam

javascript - GraphQL 查询返回错误 "Cannot return null for non-nullable field"

我有一个基本的GraphQL查询设置,如下所示:查询.js:constQuery={dogs(parent,args,ctx,info){return[{name:'Snickers'},{name:'Sunny'}];},};module.exports=Query;schema.graphql:typeDog{name:String!}typeQuery{dogs:[Dog]!}我创建了一个函数createServer()来启动服务器,如下所示:const{GraphQLServer}=require('graphql-yoga');constMutation=require('.

JavaScript 符号类型 : (non-string object keys)

什么是“Symbol”javascript类型asmentionedinthisECMAScript6draftspecification?引用规范:TheSymboltypeisthesetofallnon-StringvaluesthatmaybeusedasthekeyofanObjectproperty.EachpossibleSymbolvaluesisuniqueandimmutable.Symbolvalueshaveasingleobservableattributecalled[[Private]]whoseimmutablevalueiseithertrueorfa

javascript - Const must be initialized error in Microsoft Edge in for...of loop

我正在使用const和JavaScript的新forof循环结构。它在Chrome中运行良好,但在MSEdge中,以下代码会引发错误:for(constaof[1,2,3])console.log(a);Error:Constmustbeinitialized同样,在chrome中工作正常,边缘抛出错误。我猜它期望const变量有一个初始化值,但这就是for的全部工作,不是吗?MDN说edge支持循环,所以浏览器支持不是问题。 最佳答案 根据https://kangax.github.io/compat-table/es6,"con

javascript - 为什么 `const` 值在 `for...in` 和 `for...of` 循环内部发生变化?

Constantsareblock-scoped,muchlikevariablesdefinedusingtheletstatement.Thevalueofaconstantcannotchangethroughre-assignment,anditcan'tberedeclared.根据MDNconstant的值不能通过重新赋值改变,也不能被重新声明,所以里面for...in和for...of的工作情况如何?constdata=['A','B','C','D'];//Hereconstkeyischangedfor(constkeyindata){console.log('key

javascript - Visual Studio 任务运行程序 "SyntaxError: Use of const in strict mode."

将Win10Pro/VS2015与“网站”项目(不是asp.net,基本网站)一起使用当尝试保存/重新加载gulpfile.js时,我收到错误消息(来自TaskRunnerExplorer/输出)SyntaxError:Useofconstinstrictmode.在目前的情况下,它因“gulp-changed”而窒息我已查看可用的答案和评论:SyntaxError:UseofconstinstrictmodeSyntaxError:Useofconstinstrictmode?我已经将我的Node版本更新到最新版本:6.10.30我已经清理了缓存(npmcacheclean-f)我使

JavaScript const 关键字

JavaScript中的const关键字是否创建对不可变数据结构的不可变引用?[我假设JavaScript中存在不可变数据结构。]对于string它似乎是这样做的:varx="asdf";constconstantX=x;alert("beforemutation:"+constantX);x="mutated"alert("aftermutation:"+constantX);输出:beforemutation:asdfaftermutation:asdfhttp://jsfiddle.net/hVJ2a/ 最佳答案 首先你不是在

javascript - JSON.解析 : unexpected non-whitespace character after JSON data

我希望创建一个从4个选择菜单的选定选项派生的JSON对象。这些菜单可能在加载时选择了选项(由于服务器端技术)或者可能没有选择任何选项!使用$(document).ready()加载页面后,我的脚本就会运行……但是我遇到了JSON对象的一些问题“JSON.parse:JSON数据后出现意外的非空白字符”我希望我的JSON具有以下结构selObj={category:selectedCategory,//wecanonlyhave1category,thisisn’tgivingmeaproblem…catOptions:{optionValue:discountValue,//wecan

javascript - 插入符范围和 package-lock.json : how to get latest non-breaking versions with them?

我知道package-lock.json代表什么,但我不明白添加此文件后插入符范围是如何工作的?假设我有一个包(my-module),我想拥有所有新的非破坏性版本,而无需手动指定新版本。我安装了最新版本,这是package.json文件中的结果:“我的模块”:“^4.1.1”但是package-lock.json也得到了更新,将my-module的版本修复为4.1.1。下次my-module会出现一个新版本:4.1.2。运行npmi不会安装它,因为package-lock.json中的版本固定为旧版本。问题我如何实现npmi将下载最新的非破坏性版本的my-module而无需创建新的pa

javascript - 使用 async 和 await with export const

我无法完成这项工作...它说:await是一个保留字。是的,当然是……而且我想使用它:)怎么了?exportconstloginWithToken=async()=>{returndispatch=>{dispatch({type:SESSION_LOGIN_IN_PROGRESS,payload:true})letstoredData=awaitReadFromLocalDB('user')console.log(storedData)if(!storedData){invalidToken(null,dispatch)}else{storedData=JSON.parse(stor