jjzjj

javascript - 为什么这里的 apply() 只接受一个参数而不是两个?

我正在阅读Javascript:好的部分这本书。我对以下代码感到困惑。Function.method('curry',function(){varslice=Array.prototype.slice,args=slice.apply(arguments),that=this;returnfunction(){returnthat.apply(null,args.concat(slice.apply(arguments)));};});slice.apply(arguments)中的null在哪里? 最佳答案 arguments作为

javascript - this.initialize(arguments) 与 this.initialize.apply(this, arguments) : what's the difference?

如果您查看Backbone.js的源代码,您会看到此模式的多种用途:this.initialize.apply(this,arguments);例如,这里:varRouter=Backbone.Router=function(options){options||(options={});if(options.routes)this.routes=options.routes;this._bindRoutes();this.initialize.apply(this,arguments);};为什么不直接写this.initialize(arguments)呢?

javascript - 未捕获的类型错误 : Object [object Object] has no method 'apply'

我在创建的新网站上收到此UncaughtTypeError,但我无法找出导致该错误的原因。我在下面的链接中重现了这个问题,如果您查看浏览器的JS控制台,您会看到发生了错误,但没有其他任何反应。http://jsfiddle.net/EbR6D/2/代码:$('.newsitem').hover($(this).children('.text').animate({height:'34px'}),$(this).children('.text').animate({height:'0px'}));​ 最佳答案 确保将它们包装在异步回调

javascript - 单击 "Apply"按钮后应用 angularjs 过滤器

我有一个很大的数据列表(4000多个项目)。开始输入时-我的浏览器卡住(最多15秒)。所以我需要关闭自动过滤功能,并将过滤功能绑定(bind)到按钮点击。通过谷歌寻找答案没有结果。我该怎么做?请帮助我:)代码:和Controller:app.controller("smsCtrl",['$scope','smsData','createDialog','$http','$filter',function($scope,smsData,createDialog,$http,$filter){...} 最佳答案 我在帮助一位同事时遇到了

javascript - meteor js 铁路由器 : apply CSS change whenever route changes

我的应用程序中有主页、联系页面和其他几个与产品相关的页面。目标是仅将背景图像应用于特定路线:/homepage和/contact。如果用户离开任一路线,应用一些CSS更改。我现在正在和我主页上的一个助手一起破解这个,就像这样:Template.homepage.rendered=function(){varroute=Router.current();if(route.path=='/'){document.body.className="showBackgroundImage";}};这里部分获胜,因为这将激活css,但我需要在路线更改时停用。我还在我的router.js中尝试了以下

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 - 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 - 在 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,[