草庐IT

understanding-and-applying-polymo

全部标签

javascript - 在 JavaScript 中使用 call() 或 apply() 返回值

有没有办法在调用call()或apply()时获取函数的返回值?我的场景:我有一个函数可以与apply()函数配合使用。在对象构造函数上:varsomeObject=newSomeObject({NameFunction:"MakeNames"});在对象方法的循环中:varname="";for(vari=0;iMakeNames函数:functionMakeNames(data){returndata.FirstName+""+data.LastName;}那个varname保持为空,因为apply没有从函数返回任何值。请注意,我确信该函数已被调用并且参数已成功传递。请不要告诉我直

javascript - ES6 类中的 constr.apply(this, args)

一段时间以来,我一直在使用以下函数来创建未知类的实例:Kernel.prototype._construct=function(constr,args){functionF(){constr.apply(this,args);//EXCEPTION!}F.prototype=constr.prototype;returnnewF();};如果我使用原型(prototype),一切正常:functionPerson(name,surname){this.name=name;this.surname=surname;}varperson=Kernel._construct(Person,[

javascript - Learnyounode #6 使其模块化 : correct results AND throwing error at the same time?

我正在完成nodeschool.iolearnyounode练习#6,makeitmodular。我得到了正确的结果,但仍然有一段我不熟悉的代码出错。任何帮助都会很棒。这是结果和错误:Yoursubmissionresultscomparedtotheexpected:ACTUALEXPECTED────────────────────────────────────────────────────────────────────────────────"CHANGELOG.md"=="CHANGELOG.md""LICENCE.md"=="LICENCE.md""README.md"

javascript - 谷歌地图圈 : how to trigger an event when moved and how to obtain the new center

所以我能够在我的谷歌地图v3上制作一个圆形对象作为叠加层。我将其可编辑属性设置为true。接下来我想做的是在用户移动圆圈时获取圆心的坐标。为此,我需要某种响应事件而触发的方法。我以为我已经在初始化函数中设置了这一切,如下所示。但是,我没有收到任何警告框。所以我假设这个响应事件的函数没有被触发。functioninitialize(){cityCenterLatLng=newgoogle.maps.LatLng(cLat,cLong);options={center:cityCenterLatLng,zoom:15,mapTypeId:google.maps.MapTypeId.ROAD

javascript - Math.min.apply 为 null 返回 0

我想从数组中获取最小值。如果数据包含null值,Math.min.apply为null值返回0。请看thisJSFiddleexample.即使数组中存在null值,我如何获得真正的最小值?代码(与JSFiddle示例中的相同):vararrayObject=[{"x":1,"y":5},{"x":2,"y":2},{"x":3,"y":9},{"x":4,"y":null},{"x":5,"y":12}];varmax=Math.max.apply(Math,arrayObject.map(function(o){returno.y;}));varmin=Math.min.apply

JavaScript (ES6) : Named parameters and default values

我来自Python,我真的很喜欢设置命名参数和默认值的方式——现在看来ES6允许我做类似的事情。但我不明白为什么最后一次通话中断了:fun=({first=1,last=1})=>(1*first+2*last)console.log("-----------")console.log(fun({first:1,last:2}))console.log("-----------")console.log(fun({last:1,first:2}))console.log("-----------")console.log(fun())//Breaks 最佳答

Javascript 正则表达式模式将多个字符串(AND、OR)与单个字符串匹配

我需要根据一个相当复杂的查询来过滤一组字符串——在它的“原始”形式中,它看起来像这样:nano*AND(regulat*OR*toxic*OR((riskORhazard)AND(exposureORrelease)))要匹配的字符串之一的示例:WorkshopontheSecondRegulatoryReviewonNanomaterials,30January2013,Brussels所以,我需要使用ANDOR和通配符进行匹配-所以,我想我需要在JavaScript中使用正则表达式。我已经正确地循环、过滤并正常工作了,但我100%确定我的正则表达式是错误的——一些结果被错误地省略了

javascript - masonry 事件 : Call event after imagesLoaded and layoutComplete

这就是我想要做的。我有一个包含大量图像的网格,因此我将imagesLoaded库与masonry一起使用。这是我的CSS:.grid{opacity:0;}和HTML:imageimageimage这是我的JS:var$container=$('.grid');//initializeMasonryafterallimageshaveloaded$container.imagesLoaded(function(){$container.masonry({columnWidth:'.grid-sizer',itemSelector:'.item',gutter:'.gutter-size

javascript - Array.apply(null, Array(x) ) 和 Array(x) 之间的区别

到底有什么区别:Array(3)//andArray.apply(null,Array(3))第一个返回[undefinedx3]而第二个返回[undefined,undefined,undefined]。第二个可以通过Array.prototype.functions链接,例如.map,但第一个不是。为什么? 最佳答案 有一个区别,一个非常重要的区别。Array构造函数either接受一个数字,给出数组的长度,并创建一个具有“空”索引的数组,或者更准确地说,长度已设置,但数组实际上并不包含任何内容Array(3);//create

javascript - Vue 资源 - plugin.apply 不是函数

我有一个用Vue1构建的分页组件,为此我从Laravel分页接收数据:Novideosfoundfor"{{query}}""importeventHubfrom'../events.js'exportdefault{props:['query'],data(){return{videos:[],meta:null,showPagination:false,zeroVideos:false,}},methods:{getVideos(page){this.$http.get('/search/videos?q='+this.query+'&page='+page).then((resp