草庐IT

javascript - 扩展EventEmitter时如何解析 'this is not defined'?

这个问题在这里已经有了答案:"UncaughtReferenceError:thisisnotdefined"inclassconstructor(1个回答)关闭6年前。以下代码失败:varEventEmitter=require('events');classFooextendsEventEmitter{constructor(){this.name='foo';}print(){this.name='hello';console.log('world');}}varf=newFoo();console.log(f.print());并打印错误this.name='foo';^Ref

javascript - 为什么 push 显示 argument of type 'any[]' is not assignable to parameter of type 'never' 错误?

在这段代码中我得到了休闲错误:Argumentoftype'any[]'isnotassignabletoparameteroftype'never'varmarkers:[];this.Getlapoints(this.map.getCenter(),500000).then(data=>{for(varkeyindata){Leaflet.marker(data[key].location,//{icon:greenIcon}).addTo(this.map).bindPopup(data[key].caption);//markers.push(data[key].locatio

Javascript arguments.sort() 抛出错误 sort is not a function

只是想知道为什么我在使用以下简单的JavaScript函数时会出错functionhighest(){returnarguments.sort(function(a,b){returnb-a;});}highest(1,1,2,3);错误消息:TypeError:arguments.sort不是函数。我很困惑,因为它是一个数组(我认为)。请帮助并解释原因。非常感谢 最佳答案 因为arguments没有sort方法。请注意arguments不是Array对象,它是一个类似数组的Argumentsobject.但是,您可以使用Array

javascript - npm outdated -g Error 'Cannot read property ' length' of undefined'

我正在尝试确定我的npm安装的全局包的版本状态。在终端中运行npmoutdated-g--depth=0后,我收到此错误:npmERR!Cannotreadproperty'length'ofundefinednpmERR!Acompletelogofthisruncanbefoundin:npmERR!/Users/dangranger/.npm/_logs/2019-03-14T21_58_37_962Z-debug.log/Users/dangranger/.npm/_logs/2019-03-14T21_58_37_962Z-debug.log的内容0infoitworkedi

javascript - "require is not defined"使用 webpack 2

我在使用webpack捆绑我的应用程序时遇到问题,尽管我已经尝试了所有建议,但我在网站上看到了类似的问题,但我无法弄清楚哪里出了问题。一切都很好。但是,当我打开浏览器时显示此错误:未捕获的ReferenceError:未定义要求webpack-dist.conf.jsconstwebpack=require('webpack');constconf=require('./gulp.conf');constpath=require('path');constHtmlWebpackPlugin=require('html-webpack-plugin');constFailPlugin=r

javascript - Moment.js : Uncaught TypeError: Cannot read property 'defineLocale' of undefined at moment. js:13

当运行下面的小html文件时,我看到以下控制台日志错误:moment.js:13UncaughtTypeError:Cannotreadproperty'defineLocale'ofundefinedatmoment.js:13atmoment.js:9atmoment.js:10JSBinvarnow=moment()console.log(now);我还尝试用这个CDN链接替换对本地库的引用:https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.18.1/locale/af.js有人知道这个错误是什么吗?

javascript - 获取 `TypeError: jest.fn is not a function`

我正在尝试使用Jest创建以下单元测试。jest.dontMock("pointsAwardingActions.js");describe("pointsawardingactions",()=>{describe("awardpoints",()=>{it("shoulddispatchbeginajaxaction",()=>{varpointsAwardingActions=require("pointsAwardingActions.js");constmockedDispatch=jest.fn();});});});但在运行npmtest后我收到以下错误。TypeErro

javascript - 是什么导致错误 "Uncaught TypeError: number is not a function"

我有一个更新表单的onchange事件,在更新过程中它调用一个函数来计算运费。我不确定为什么,但是当我尝试调用该函数时出现以下错误:未捕获的类型错误:数字不是函数shipping函数如下所示:functionshipping(weight){varflatswitch(weight){case1:case2:case3:flat=32.00;break;case4:flat=18.50;break;case5:flat=15.80;break;case6:flat=14.00;break;case7:flat=12.71;break;case8:flat=11.75;break;cas

javascript - 'is an instance of' 在 Javascript 中是什么意思?

这个问题的答案:WhatistheinitialvalueofaJavaScriptfunction'sprototypeproperty?有这样一句话:Theinitialvalueofprototypeonanynewly-createdFunctioninstanceisanewinstanceofObject据我所知,Javascript没有类,因此“实例”这个词在我脑海中没有意义。应该如何解释Javascript中的“实例”?抱歉,我没有足够的代表将我的问题放在该答案的评论线程中。 最佳答案 你说得对,JavaScript

javascript - react native v0.56 : Cannot read property 'filename' of undefined at PluginPass. JSXOpeningElement

我刚刚将ReactNative从0.55更新到0.56。但是,当我尝试运行代码(react-nativerun-android或run-ios)时,捆绑停止到这一点:Loadingdependencygraph,done.error:bundlingfailed:TypeError:Cannotreadproperty'filename'ofundefinedatPluginPass.JSXOpeningElement({path_to_my_project}/react-native/node_modules/babel-plugin-transform-react-jsx-sour