草庐IT

Typora使用

全部标签

javascript - mocha js 断言在使用 promise 时挂起?

"usestrict";letassert=require("assert");describe("Promisetest",function(){it('shouldpass',function(done){vara={};varb={};a.key=124;b.key=567;letp=newPromise(function(resolve,reject){setTimeout(function(){resolve();},100)});p.then(functionsuccess(){console.log("success---->",a,b);assert.deepEqual

javascript - 使用 Promises 通过 Bluebird promises 库在另一个函数中调用函数

我有3个NodeJs函数。我想在这里做的是,我想调用normalizeFilePath并获取规范化路径,然后检查该文件是否存在normalizedFilePath最后这些,如果文件不存在则创建一个文件。这是使用promises(Bluebird)的第一天,我是NodeJS和JavaScript的新手。下面的代码结构越来越复杂。当然,这根本不是一个好主意。varcreateProjectFolder=function(projectName){};varcheckFileExistance=function(filePath){returnnewpromise(function(reso

javascript - 在新路由器上使用订阅功能时出现 Angular 2 typescript 错误 (rc 1)

我正在尝试使用新路由器为我的Angular2应用程序设置身份验证。有人建议尝试以下操作:constructor(private_router:Router){}ngOnInit(){this._router.subscribe(next=>{if(!userIsLoggedInOrWhatever){this._router.navigate(['Login']);}})}然而,这个问题是这会导致typescript错误(app.component.ts(47,22):errorTS2339:Property'subscribe'doesnotexistontype'Router'.这

javascript - 刷新服务 worker 中使用 importScripts 导入的脚本

我有一个网站,其中有一个serviceworker,例如://ImportascriptfromanotherdomainimportScripts('https://example.com/script.js')假设script.js更新了一些新代码,并且由于推送事件激活了serviceworker(用户在此期间没有再次访问我的网站)。importScripts是在每次激活serviceworker时检查更新,还是在首次安装serviceworker时只下载一次script.js?有什么方法可以让服务worker每次收到推送消息时刷新服务worker代码(尤其是导入的脚本)?

javascript - 如何使用 Angular 的装饰器模式来增强指令的链接功能?

我正在研究Angular库并寻找一种使用装饰器模式扩展指令的方法:angular.module('myApp',[]).decorator('originaldirectiveDirective',['$delegate',function($delegate){varoriginalLinkFn;originalLinkFn=$delegate[0].link;return$delegate;}]);使用此模式扩充原始指令的最佳方式是什么?(示例用法:在不直接修改其代码的情况下对指令进行额外的监视或额外的事件监听器)。 最佳答案

javascript - 为什么我不能使用由 require() 导入的 javascript 文件中的函数?

我开始使用electron.在index.htmlofelectron-quick-start使用require()包含一个JavaScript文件。//Youcanalsorequireotherfilestoruninthisprocessrequire('./renderer.js')现在我在renderer.js中定义了一个名为flash()的简单函数,以及一个日志输出:functionflash(text){alert("Text:"+text+"!");}console.log("Rendererloaded.");启动Electron应用程序后,我在开发工具的控制台中输出

javascript - 将 fullcalendar 与 webpack 结合使用

我使用npm、webpack和FullCalendar,但在使用fullcalendar时,浏览器控制台出现以下错误:main.js:37556UncaughtTypeError:(0,_jquery2.default)(...).fullCalendarisnotafunction我该如何解决这个问题?我使用FullCalendar3.0.0-beta和jquery3.1.0。我的代码如下。index.js:import$from'jquery'importjQueryUIfrom'jquery-ui'importmomentfrom'moment'importfullCalenda

javascript - 使用 jQuery 更改值

我有以下内容:3我有以下jqueryvarreplaceit=$(this).closest(':has(.label-info)').find('.label-info').text();变量的值总是一个整数,但不会总是3:ie:1,2,3,4,5.我已经尝试了很多方法,但无法获得更改的值。我最近的尝试是:return$(this).closest(':has(.label-info)').html().replace(replaceit,(replaceit-1));我的最终结果是,无论“lable-info”的当前值是多少,都减去1,然后用这个新结果切换它。因此,基于值3的新跨度

javascript - 在自定义事件上使用 enzyme 模拟?

可以在自定义事件上使用Enzyme的方法.simulate()。例如://Code//Testconstelement=shallow();element.simulate('foo');这是应该使用Enzyme测试自定义事件的方式,还是使用s.th.的更好方法?喜欢://Testconstelement=shallow();element.props.onFoo() 最佳答案 似乎没有实现自定义事件的.simulate()。有一个issue在github上,讨论了这个主题,其中一位Enzyme维护者建议使用您提供的第二种方法:wr

javascript - 使用 jsdoc 创建自定义标签

我正在尝试在jsdoc3.4.2中创建自定义标签。config.json文件是{"tags":{"allowUnknownTags":true,"dictionaries":["jsdoc","closure"]},"source":{"include":["app/"],"exclude":[],"includePattern":".+\\.js(doc|x)?$","excludePattern":"(^|\\/|\\\\)_"},"plugins":["plugins/custom-tags.js"],"templates":{"cleverLinks":false,"monos