草庐IT

function-constructor

全部标签

javascript - Cloud Functions for Firebase onWrite 超时

我返回交易promise,它应该在停止功能之前等待交易完成。事务执行得很好,但promise似乎永远不会解决。我在Firebase控制台中看到这个函数总是在60秒后超时。constfunctions=require('firebase-functions');constadmin=require("firebase-admin");constdb=admin.database();exportletcountFollowers=functions.database.ref('followers/{followee}/{follower}').onWrite(event=>{constf

javascript - `function(*=)` 在 JSDoc 风格的代码注释中意味着什么?

我正在使用JSDoc风格编写一些代码注释,想知道*=在@returns{function(*=):*}中意味着什么,它由WebStorm生成。我尝试搜索JSDocwiki和usejsdoc.org但没有结果。下面是我的代码:/***Getrecorddatalistenergenerator.*@param{Function}createProps*@returns{function(*=):*}//**generatedbywebstorm***/exportfunctiongetRecordCustomDataListener(createProps){return(callbac

javascript - "Partial Function Application"在 Javascript 上下文中是用词不当吗?

我和我的一个friend正在讨论Javascript中的柯里化(Currying)和偏函数应用,关于两者是否可以实现,我们得出了截然不同的结论。我想到了Function.prototype.curry的实现,这是我们讨论的基础:Function.prototype.curry=function(){if(!arguments.length)returnthis;varargs=Array.prototype.slice.apply(arguments);varmmm_curry=this,args;returnfunction(){varinner_args=Array.prototy

javascript - 我是否正确理解了这个 Function.prototype.call() 代码?

代码:varcontent=Array.prototype.map.call(document.getElementsByTagName("p"),function(e){returne.innerHTML;});来自p.367ofJavaScript:权威指南,第6版。这是我认为这段代码中发生的事情。变量content正在分配.map()的结果调用NodeListdocument.getElementsByTagName("p")返回的段落标签数量..map()方法是从Array.prototype访问的,及其this值设置为段落标记NodeList使用.call().自.map()

javascript - Angular Testing : Spy a function that was executed on the initialize of a controller

我一直在尝试监视在Controller初始化时执行的函数,但测试总是失败。我一直在尝试执行$scope.$digest()但它不起作用,但是在控制台中,我看到该函数已被调用。我想不通,有人可以向我解释为什么它不起作用吗?代码笔示例:http://codepen.io/gpincheiraa/pen/KzZNbyControllerfunctionController($stateParams,$scope){$scope.requestAuthorization=requestAuthorization;if($stateParams.requestAuthorization===tr

javascript - .then(functionReference) 和 .then(function(value){return functionReference(value)}) 之间有区别吗?

给定一个用于处理Promise值的命名函数functionhandlePromise(data){//dostuffwith`data`returndata}a)将命名函数handlePromise作为对.then()的引用传递promise.then(handlePromise)b)使用匿名函数或命名函数作为.then()的参数,并以Promise值作为参数返回命名函数handlePromise在传递给.then()的匿名或命名函数的主体内promise.then(function/*[functionName]*/(data){returnhandlePromise(data)})

javascript - 类型错误 : 'undefined' is not a constructor (evaluating 'new JdRes())

我正在为AngularController编写jasmine测试规范。在这里,我收到错误TypeError:'undefined'isnotaconstructor(evaluating'newJdRes())-虽然我已经将其定义为JdRes=jasmine.createSpy('JdRes');Controller中的代码段如下function(myService,$scope,$attrs,$q,$parse){'usestrict';varJdRes,resource;JdRes=myService('JdRes');resource=newJdRes();}

JavaScript:在不使用 new + Constructor 的情况下基于原型(prototype)创建对象

这可能吗?我的想法:原型(prototype)本质上是构造函数的属性(无论是原生构造函数,如Function、String或Object,还是您自己的自定义构造函数),只有“new”关键字能够利用构造函数及其对象原型(prototype)创作我错过了什么吗? 最佳答案 你是对的,但是现在在ECMAScript第5版中,Object.create方法能够使用另一个对象作为原型(prototype)来创建对象实例:varproto={foo:1};varobj=Object.create(proto);在上面的示例中,obj将被创建,它

javascript - JS 继承 : calling the parent's function from within the child's function

JS对象模型肯定有不明白的地方。来自这些资源:PrototypesBasicOOPinJS-InheritanceObject.create()我收集了我认为或认为是对象模型的准确心理表征。在这里:所有对象都有一个属性,文档将其称为[[Prototype]]。[[Prototype]]可以被认为是对对象父对象的引用。更准确地说:Thereferencetothe[parent's]prototypeobjectiscopiedtotheinternal[[Prototype]]propertyofthenewinstance.(source1)您可以使用Object.getProtot

javascript - 类型错误 : is not a function typescript class

我在typescript类中遇到以下错误,无法理解原因。我所做的只是尝试调用传递token的辅助函数。错误:posterror:TypeError:this.storeTokenisnotafunction(…)类:/***AuthenticationService:**Containsthehttprequestlogictoauthenticatethe*user.*/import{Injectable}from'@angular/core';import{Http,Response,Headers,RequestOptions}from'@angular/http';import