草庐IT

application_apply

全部标签

javascript - underscore.js: _.zip.apply 示例

我想看一个使用underscore.js的_.zip.apply的例子。在underscoredocumentation写成:Ifyou'reworkingwithamatrixofnestedarrays,zip.applycantransposethematrixinasimilarfashion.但是,文档没有提供示例。 最佳答案 这是您对apply的标准用法:_.zip.apply(null,[['foo','bar'],[0,1]])这将导致以下结果:[['foo',0],['bar',1]]

javascript - "Resource interpreted as script but transferred with MIME type application/json"使用 Youtube 的 JavaScript API

我在使用GoogleChrome的JavaScript控制台时收到“资源解释为脚本但使用MIME类型application/json传输”的错误消息。我目前正在本地计算机上运行以下代码:varURL="";varYOUTUBE_ROOT="http://gdata.youtube.com/feeds/api/videos?alt=jsonc&v=2";varstart_index="&start-index=1";varcallback="&jsonp=?"functionsearchYouTube(){varq=encodeURIComponent(jQuery("#query").

javascript - Javascript "apply"函数在 window.external 扩展对象中不存在

我在IE8(也可能是任何IE版本)上使用javascript扩展(又名window.external)来公开某些功能。我正在尝试调用apply函数,该函数(根据here应该是)在window.external对象的每个JS函数中原生嵌入函数,但浏览器不断抛出异常,表明该函数不存在apply函数。例如,这段代码有效:functiononDataReceived(url,success,status,data,errorMessage){alert(onDataReceived);}functioninnerTest(){alert(arguments[0]+","+arguments[1

javascript - 为什么构造函数中需要apply()函数

functionSet(){//Thisistheconstructorthis.values={};this.n=0;this.add.apply(this,arguments);//Allargumentsarevaluestoadd}//Addeachoftheargumentstotheset.Set.prototype.add=function(){/*Codetoaddpropertiestotheobject'svaluesproperty*/returnthis;};这是“Javascript:权威指南”中用于创建“Set”类的代码的开头。我试图合理化apply()的必

javascript - 数据类型 'application/json' 与 'json'

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:$.ajax-dataType我正在使用jQuery1.8.2,由于某些原因'application/json'不起作用,但是'json'可以用作dataType到标准的jqueryajax调用。这是一个小故障吗?版本相关的差异?还是两者之间存在既定差异?$(document).ready(function(){$.ajax({type:"POST",url:'',//dataType:"application/json",

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 - 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 - 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