草庐IT

function_that_can_throw

全部标签

javascript - Javascript 函数定义中的句点 (function window.onload(){})

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:JavaScriptFunctionSyntaxExplanation:functionobject.myFunction(){..}我最近看到了一些(遗留的)javascript代码,如下所示:functionwindow.onload(){//somecode}这对我来说看起来不像有效的javascript,因为您不能在标识符中使用句点,但它似乎在IE8中有效。我假设它相当于:window.onload=function(){}我在Chrome和IE9中尝试过相同的代码,但它们都引发了语法异常,所以我认为

javascript - "function*()"在nodejs中是什么意思?

这个问题在这里已经有了答案:Whatis"function*"inJavaScript?(4个答案)关闭8年前。我遇到了这个惯用语:function*(){...}来自这个页面https://github.com/jmar777/suspend并且不确定它是做什么的。谁能解释一下?谢谢!

javascript - IIFE void function() vs (function()) 在括号中使用 void 与包装的区别

创建模块的常见做法是将它们包裹在括号中,这样您就不会在模块外泄漏任何变量(在连接等时)。还有void运算符,它计算给定的表达式并返回undefined。(参见MDN)我想知道更喜欢在括号中包装函数而不是使用void的原因是什么。它是历史的,它是否与串联有关,否则?我知道当其中一个文件缺少分号时,您可能会遇到连接问题,这会导致严重的问题,直到您注意到为止。例子例如,module1.js(注意缺少的逗号):(function(){returnfunction(){console.log('module1.Ishouldnotbecalled');};})()和module2.js:(fun

javascript - react : 'this.state' is undefined inside a component function

我在组件内的函数中访问this.state时遇到问题。我已经找到了this关于SO的问题并将建议的代码添加到我的构造函数中:classGameextendsReact.Component{constructor(props){super(props);...this.state={uid:'',currentTable:'',currentRound:10,deck:sortedDeck};this.dealNewHand=this.dealNewHand.bind(this);this.getCardsForRound=this.getCardsForRound.bind(this)

javascript - JS : Get inner function arguments in asynchronous functions and execute callback

我尝试编写返回异步函数的所有结果的函数,并执行一个回调,将其插入数组并记录每个异步函数的结果。作为一个服务员,当所有的菜都吃完了就端上来。我不明白如何获得应该作为结果返回的子参数。任务代码和我不工作的解决方案如下:任务:vardishOne=function(child){setTimeout(function(){child('soup');},1000);};vardishTwo=function(child){setTimeout(function(){child('dessert');},1500);};waiter([dishOne,dishTwo],function(res

javascript - Codility 训练 : Find the maximal number of clocks with hands that look identical when rotated

这是问题的链接:https://codility.com/demo/take-sample-test/clocks问题是我不能从中得到100分(只有42分)。运行时间还可以,但对于某些测试用例,代码给出了错误的答案,但我无法弄清楚问题出在哪里。有人可以帮帮我吗?这是我的代码:functionrotate(arr){varmin=arr.reduce(function(a,b){returna>b?b:a});while(arr[0]!=min){varfirst=arr.shift();arr.push(first);}}functionsolution(A,P){varpositio

javascript - Jade : load external javascript and call function

我正在学习Express/Node/Jade,现在我想在Jade文件中包含一个来自公共(public)文件夹的javascript文件,只用于该页面。例如,在jade文件中我输入:script(src='/javascripts/test.js')在test.js里面我有一个函数functioncheck_test(){return"It'sworking!"}然后我尝试通过以下方式调用Jade中的函数-vartest_response=check_test()比我得到的错误说“undefinedisnotafunction”和test.js根本没有加载。显然Jade不会加载文件,它们

javascript - Meteor:为什么将 function() { } 切换为 () => { } 会丢失我的数据上下文?

所以我正在试验ES6,安装了grigio:babel包,并开始检查我的es5代码并在遇到问题时将其更新为一些新的ES6语法。最初我的模板助手看起来像这样:Template.exampleTemplateName.helpers({exampleHelper:function(){//returnsanarrayfromMongoCollection}});在Blazeeach循环中使用{{#eachexampleHelper}}{{/each}}如您所料,我在这个事件循环中的元素的所有事件处理程序都可以访问exampleHelper通过this关键字。this.exampleField

javascript - 错误 : Task x can't support dependencies that is not an array of strings

我正在关注thistutorial如何开始使用gulp和browserify(以及其他插件)。结构如下:.├──gulpfile.js└──gulp  ├──index.js  └──tasks  ├──browserify.js  └──minifyCss.js/*gulpfile.js*/vargulp=require('./gulp')(['minifyCss','browserify']);gulp.task('default',['minifyCss','browserify']);/*index.js*/vargulp=require('gulp');module.expo

javascript - Foundation 6 - 控制台警告 : Tried to initialize magellan (any JS plugin) on an element that already has a Foundation plugin

我使用bower安装了Foundation6。每次我使用任何Foundation6-JavaScriptbasedplugin时,我都会在控制台中收到多个warning。确切的警告:TriedtoinitializemagellanonanelementthatalreadyhasaFoundationplugin.我的脚本包括如下所示:$(document).foundation();该警告由foundation.js中180行的以下代码触发://Foreachpluginfound,initializeit$elem.each(function(){var$el=$(this),o