草庐IT

in-function

全部标签

javascript - Douglas Crockford 所说的 'constructed in a different window or frame' 是什么意思?

DouglasCrockford在编写is_array()测试时说它将无法识别在不同窗口或框架中构造的数组,这是什么意思?varis_array=function(value){returnvalue&&typeofvalue==='object'&&value.constructor===Array;为什么以下内容跨窗口和框架工作?varis_array=function(value){returnvalue&&typeofvalue==='object'&&typeofvalue.length==='number'&&typeofvalue.splice==='function'&

javascript - 未捕获的 RangeError : Invalid array length in Chrome version 36. 0.1985.5 dev -m

我有一个谷歌地图API设置Here,并且只有GoogleChrome会抛出“未捕获的RangeError:无效的数组长度”。这里是有问题的代码:varmap;varphoenix=newgoogle.maps.LatLng(33.551946,-112.109985);varlocOne=newgoogle.maps.LatLng(33.541061,-112.293369);varlocTwo=newgoogle.maps.LatLng(33.37738,-111.833271);varlocThree=newgoogle.maps.LatLng(33.454742,-112.099

javascript - Function.prototype.bind 在 IE 中不起作用,即使在应该支持它的版本中也是如此

以下脚本在IE9、IE10、IE11中不起作用vara=location;varb='toString'varc=a[b].bind(a);c();//"InvalidcallingobjectinIE"有什么解决方法吗?编辑-链接问题中提供的MDN垫片不起作用!!它们适用于IE8!我对IE>8的问题是“支持”Function.bind。 最佳答案 InternetExplorer因允许您直接访问主机对象(如location和console)而臭名昭著,而无需像Chrome和Firefox那样在它们周围提供“Javascript包装

使用 `new Function()` 优化 Javascript

在阅读文档时,我发现了一个可以大大提高javascript性能的简单优化。原代码:functionparseRow(columns,parser){varrow={};for(vari=0;i优化代码:varcode='return{\n';columns.forEach(function(column){code+='"'+column.name+'":'+'parser.readColumnValue(),\n';});code+='};\n';varparseRow=newFunction('columns','parser',code);在这里找到:https://github

Javascript 和 Canvas : How to get rid of that Moiré effect in my gyroscope

出于乐趣,我使用Javascript和Canvas制作了那个小玩具陀螺(陀螺仪?)。不幸的是,它有一个丑陋的莫尔效应(见下面的截图)。http://jsfiddle.net/8bac4s9v/1/functiondraw(){varc=document.getElementById("myCanvas");varctx=c.getContext("2d");ctx.imageSmoothingEnabled=false;varcolors=[['blue','yellow'],['white','pink'],['green','red'],['white','black'],['gr

javascript - sails .js : post text input and a file in the same time

我想在表单中发送一个文件和一个隐藏的输入文本。在我的Controller中,request.body等于{}。当我删除enctype="multipart/form-data"它适用于我的文本但不适用于我的文件。上传我的文件:uploadFile.upload({saveAs:fileName,dirname:directoryName},functiononUploadComplete(err,files){...............});我的Controller:importXLS:function(req,res){varuploadFile=req.file('xlsx_f

javascript - `Function` 创建的这些函数有什么区别?

1.varf=newFunction("a","b","returna+b")2.varf2=Function("a","b","returna+b")f和f2都是匿名函数。f(1,2)和f2(1,2)都返回3。那么两者之间有什么实际的内部差异吗?Function是否在内部返回一个函数对象?与使用Function作为构造函数newFunction(...)的区别? 最佳答案 来自ECMAScript5.1specs:WhenFunctioniscalledasafunctionratherthanasaconstructor,itc

JavaScript ES6 : Grouping methods in es6 classes?

我们中的一些人正在尝试创建一个JavaScript库以在RESTfulAPI上快速运行JSON查询。我想做的是根据它们的目的对一组方法进行分组。例如;通过API,我能够获取用户属性。我不想将所有这些方法都放在主对象下,而是将它们分组在API类对象中。即转换这个:myAPI.getUserById()为此:myAPI.User.getByID()myAPI.User.getByName()我们将使用下面的代码作为一个简单示例。我如何将我的用户方法嵌套在myAPI类的用户对象中??classmyAPI{constructor(url){this.url=url;//Codetoconnec

javascript - angular2-in-memory-web-api 404 错误

我正在尝试按照本指南以Angular2构建5分钟的应用程序:https://angular.io/docs/ts/latest/tutorial/toh-pt6.html.在http部分,我添加了一个假服务器,但我收到404错误,因为angular2-in-memory-web-api.http://localhost:4200/vendor/angular2-in-memory-web-api/in-memory-backend.service.jsFailedtoloadresource:theserverrespondedwithastatusof404(NotFound)我试图

javascript - 重组 "withReducer": justification of async reducer function call

我正在使用withReducerHOC并注意到这种行为:例如,在点击处理程序上调用它:importReactfrom'react'import{withReducer}from'recompose'import{compose}from'ramda'exportdefaultcompose(withReducer('state','dispatch',(state,{value})=>{console.log(value)return{...state,value}},{value:'zero'}))((props)=>{const{dispatch,state}=props,onCl