草庐IT

fcatch-undefined-behavior

全部标签

javascript - 遍历 JSON 数组给出 "undefined"结果

这个问题在这里已经有了答案:Whyisusing"for...in"forarrayiterationabadidea?(28个答案)JavaScriptfor...invsfor(22个答案)关闭7年前。我有一个从AJAX解析的JSON字符串(在responsevar中):JSON{"TheArray":[{"AlmostThere":{"whatWeAreLookingFor":"Hello"}},{"AlmostThere":{"whatWeAreLookingFor":"Goodbye"}}]}正在解析的JSONvarjsonData=JSON.parse(response);

javascript - 开 Jest + 火力地堡 : TypeError: Cannot read property 'defineProperties' of undefined

我目前正在做一个ReactNative项目,想使用FirebaseJSSDK。为了熟悉它的所有API,我想用Jest编写一些学习测试。这是我的测试:importFirebasefrom'firebase';describe('Firebase',function(){it('shouldwork',function() {expect(null).toBeNull()})});不幸的是我收到了这个错误:●测试套件运行失败TypeError:Cannotreadproperty'defineProperties'ofundefinedatnode_modules/firebase/app

javascript - 为什么 typescript 不提示某些 undefined variable

我有以下示例:classUncle{constructor(publicname:string){}talk(){return"Hellomynameis"+name;}}letp:Uncle=newUncle("Jo");console.log(p.talk());对于某些变量名,typescript(目前版本2.1.4)不会提示它们没有在您的程序中定义(在方法讨论中,名称是在没有这个的情况下使用。)。name就是其中之一。如果我将变量重命名为firstName,编译器会正确地提示...errorTS2663:Cannotfindname'firstName'.Didyoumeant

javascript - Vuex + VueJS : Passing computed property to child is undefined

我正在阅读这个documentationonVuecomponents,但使用Vuex数据作为我的组件属性。在这个例子中,如果country_id在data方法中,它工作正常。但是当country_id是一个从Vuexstore返回数据的计算属性时,子组件的internalValue总是被初始化为undefined。我做错了什么?父组件:exportdefault{computed:{country_id(){returnthis.$store.state.user.country_id}},mounted:function(){this.$store.dispatch('user/l

javascript - 3 个变量的总和 : strange behavior

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:IsJavaScript'sMathbroken?Whycan'tdecimalnumbersberepresentedexactlyinbinary?下一段代码的结果是什么:if(0.3==(0.1+0.1+0.1)){alert(true);}else{alert(false);}这很奇怪,但结果会是错误的。原因是0.1+0.1+0.1会是0.30000000000000004如何解释这种行为?

javascript - JavaScript 中全局作用域中存在 undefined variable 的原因是什么?

我发现很多关于undefined作为值的讨论,例如如何检查是否相等等等。但是undefined作为全局变量存在的“工程”原因是什么?对面没有null变量...console.log(undefinedinthis);//logstrueconsole.log(nullinthis);//logsfalse 最佳答案 在JavaScript中,null是一个保留字;undefined不是,但由环境实现作为一个全局变量,其值为undefined。您会注意到您可以更改undefined的值,但不能更改null的值,except严格模式(会

javascript - 为什么 window 或 document 不能设置为 undefined 或 null?

这可能是个愚蠢的问题,但我还没有找到答案。为什么我们不能做到以下几点?window=undefined或document=undefined我知道这些是全局变量并且在浏览器中可用,但考虑到JavaScript的工作原理,这不可能吗?每次我们尝试访问它们时都会重新评估它们吗?我也很想知道window或document对象如何在将它们设置为随机值后保持原样...可能是number或undefined或null。 最佳答案 根据thestandard:ThewindowattributemustreturntheWindowobject'

javascript - 执行 Action 时 redux 出错 : Uncaught type error: cannot read property 'type' of undefined

刚刚接触React。我想这是一个基本问题,但我不明白为什么reducer没有被解雇或更新状态:我的HomeView.js:....const{localeChange,counter,locale}=this.propsreturn(increment(7)}>Increment.....)constmapStateToProps=(state)=>({locale:state.locale,counter:state.counter})exportdefaultconnect(mapStateToProps,{localeChange,increment})(HomeView)我的r

javascript - (React-Native) undefined 不是评估 'new FormData()' 的构造函数

在过去的两天里,我一直在努力解决这个问题,但无法弄清楚。我不明白这个错误。这是我的代码:try{varformData=newFormData();}catch(error){console.error('FormDataERROR',error);}这是错误:017-06-2113:49:02.761[error][tid:com.facebook.React.JavaScript]'FormDataERROR',{[TypeError:undefinedisnotaconstructor(evaluating'newFormData()')]line:98419,column:36

javascript - 如何解决 “cannot call method … of undefined” 错误?

functioncalcRoute(){varstart=document.getElementById("start_").value;varend=document.getElementById("end_").value;varrequest={origin:start,destination:end,travelMode:google.maps.TravelMode.DRIVING};directionsService.route(request,function(response,status){if(status==google.maps.DirectionsStatus.