草庐IT

test_register_without_subscriptio

全部标签

javascript - 为什么 RegEx.test 会在后续调用中更改结果?

这个问题在这里已经有了答案:WhydoesaRegExpwithglobalflaggivewrongresults?(7个答案)关闭7年前。为什么以下从true变为false;varr=/e/gi;r.test('e');//truer.test('e');//false然后继续切换true,false,true,false......

javascript - Regex.test() 给出真假顺序?

任何人都可以解释一下,为什么本地Regex变量和非本地Regex变量有不同的输出。varregex1=/a|b/g;functionisAB1(){returnregex1.test('a');}console.log(isAB1());//trueconsole.log(isAB1());//falseconsole.log(isAB1());//trueconsole.log(isAB1());//falsefunctionisAB2(){varregex2=/a|b/g;returnregex2.test('a');}console.log(isAB2());//truecons

javascript - 为什么 "setter is defined without getter"是 JSHint 错误?

引用jsfiddlevarobj={setbla(k){console.log(k);}};JSHint将此标记为“setter是在没有getter的情况下定义的”。我确信有办法关闭它,但为什么这是一个错误呢?我所看到的所有JSHint标志都有一个合理的解释。我想不出这是一件坏事的原因。 最佳答案 我认为JSHint没有充分的理由对这种情况发出警告。我在规范(http://www.ecma-international.org/publications/standards/Ecma-262.htm,第30-31页)中没有看到任何内容要

javascript - 使用 Chutzpah 运行 QUnit (TypeScript) 测试给出 "Called start() outside of a test context while already started"

我有一个相当简单的重现,结果我不明白。确保安装了Chutpah测试适配器4.0.3。使用VisualStudio2013执行以下步骤:创建一个新的.NET4.5.1类库项目;添加NuGet包qunit.TypeScript.DefinitelyTyped0.1.7;将TypeScript文件file1.ts添加到项目中,内容如下:///QUnit.test("QUnitisworking",assert=>assert.ok(true));在该文件内右键单击并从上下文菜单中选择“运行JS测试”。我可以确认file1.js是按预期生成的。结果是没有运行任何测试,测试资源管理器没有显示测试

javascript - 如何在规范文件中注入(inject)服务 Angular Testing (Jasmine/karma)

我刚开始编写Angular单元测试用例。我在我的Controller文件(.ts)中注入(inject)一项服务。我将如何在规范文件中注入(inject)服务文件。代码如下:app.component.tsgetSortData(){this.sortService.sortNumberData(this.data,'name','asce');}sort.service.tssortNumberData(data,rendererKey,type){//data.sort((elem1,elem2)=>{////ifnumberisundefined,thenassigning`MA

javascript - '错误 : Unexpected request' during Karma Angular Unit Test

运行gruntkarma时,其中一个指令的测试在尝试获取模板时失败。我使用ng-html2js作为预处理器。这是我的一些karma.conf.jsplugins:['karma-chrome-launcher','karma-jasmine','ng-html2js','karma-ng-html2js-preprocessor'],preprocessors:{'app/scripts/directives/**/*.html':'ng-html2js'},ngHtml2JsPreprocessor:{moduleName:'templates'}在我的测试中,我有以下内容:'use

javascript - JS文件中的System.register是什么意思?

在Angular2中使用指令时,JS文件中的System.register是什么意思。 最佳答案 我认为这个问题并不特定于angular2中的指令,它是关于ES6、TypeScript和其他使用SystemJS的现代编译器的一般问题。简短的回答-它是由System.js创建的包装器,用于隔离代码并注入(inject)外部依赖项。这段代码:import{pasq}from'./dep';vars='local';exportfunctionfunc(){returnq;}exportclassC{}将生成:System.registe

javascript - 微软表面 : How do I allow JavaScript touch/drag events to work without being intercepted by the browser?

我的网站上有一张GoogleMapsmap,但当它与MicrosoftSurface平板电脑一起使用时,“平移”手势会被浏览器拦截——它会尝试转到下一个浏览器窗口。如何允许浏览器忽略平移(拖动事件)以使map正常运行?转到maps.google.com,map完全可以拖动,因此Google必须采用一种解决方法。 最佳答案 根据MS的“指针和手势事件”指南(此处:http://msdn.microsoft.com/en-us/library/ie/hh673557%28v=vs.85%29.aspx#Panning_and_zoomi

javascript - 未处理的 promise 拒绝警告 : This error originated either by throwing inside of an async function without a catch block

我的Node-Express应用出现以下错误UnhandledPromiseRejectionWarning:Unhandledpromiserejection.Thiserrororiginatedeitherbythrowinginsideofanasyncfunctionwithoutacatchblock,orbyrejectingapromisewhichwasnothandledwith.catch().(rejectionid:4)至少可以说,我创建了一个看起来像这样的辅助函数constgetEmails=(userID,targettedEndpoint,headerA

javascript - JS : detect right click without jQuery (inline)

我正在调用一个函数,它构建了一个包含多个链接的表。我想检查是否用鼠标右键或左键单击了链接。我尝试将以下部分添加到超链接。onmousedown="functionmouseDown(e){switch(e.which){case1:alert('left');break;case2:alert('middle');break;case3:alert('right');break;}}"但是如果我点击一个链接什么也不会发生。 最佳答案 html:aaa​​​​​​​​​​​​​​​​​​​​​​​​​​​JavaScript:func