jjzjj

anonymous-function

全部标签

javascript - 使用 AngularJS 时出现 ".then() is not a function"错误

这是我的JS:self.obj={}self.obj.accessErrors=function(data){varcerrorMessages=[];for(propindata){if(data.hasOwnProperty(prop)){if(data[prop]!=null&&data[prop].constructor==Object){self.obj.fetch[accessErrors](data[prop]);}else{cerrorMessages.push(data[prop]);}}}returncerrorMessages;};self.obj.fetch={

javascript - Angular : Update A Function In RealTime

我有一个Controller:$scope.timeAgoCreation=function(order){returnmoment(order.createdAt).fromNow();};在View中:{{timeAgoCreation(order)}}它返回正确的值:9分钟前。但是这个值不是实时更新的。我必须刷新页面。是否可以让它实时更新? 最佳答案 只需将此功能添加到Controller中(不要忘记注入(inject)$timeout服务):functionfireDigestEverySecond(){$timeout(f

javascript - Bluebird.JS Promise : new Promise(function (resolve, reject){}) vs Promise.try(function(){})

我什么时候应该使用哪个?以下是一样的吗?新的Promise()示例:functionmultiRejectExample(){returnnewPromise(function(resolve,reject){if(statement){console.log('statement1');reject(thrownewError('error'));}if(statement){console.log('statement2');reject(thrownewError('error'));}});}Promise.try()示例:functiontryExample(){return

javascript - 如何使用 Cloud Functions for Firebase 与 .onWrite 或 onchange 比较新旧值?

让我们采用以下数据结构:现在我想用Firebase函数刷新accessTokenFacebook。我测试了两个选项:onWrite和:onChangedonWrite对我来说看起来最好,但具有以下功能:exports.getFacebookAccessTokenOnchange=functions.database.ref('/users/{uid}/userAccountInfo/lastLogin').onWrite(event=>{constlastLogin=event.data;letdateObject=newDate();letcurrentDate=dateObject

javascript - 匿名函数的上下文是什么?

我有这样的代码:functiondemo(){this.val=5;function(){this.val=7;}();}现在,当我在firefox或chrome控制台中执行此代码时,它会出现语法错误。我不明白为什么这是一个错误,因为我读过javascript函数是对象,所以当我调用匿名函数时,它里面的this指向函数演示并且应该更改val到7,所以如果我这样做了varx=newdemo();x.val;//shouldgive7但是当我这样做的时候functiondemo(){this.val=5;varf=function(){this.val=7;}();}window.val;

javascript - jQuery控制台报错: $(this). effect is not a function

我已经盯着我的代码看了好几个小时,现在我想弄清楚为什么这个看似简单的jQuery游戏不起作用:title"test"test2011test$(document).ready(function(){$(".tNail").click(function(){$(this).effect("scale",{percent:200,direction:'both'},1000);});});我试过使用noConflict()无济于事。如果有人能阐明一些问题,我将不胜感激。谢谢。 最佳答案 啊,再看一遍,我觉得报错信息大

javascript - 自调用函数中递归函数的 setTimeout()

我想将我的代码作为一个self调用的匿名函数来分发,正如我看到的那样。此外,在我的代码中,我必须监视另一个库加载,以便我可以在它可用时使用它。(function(window,document,undefined){staffHappens();varinitMyLib=function(){if(typeof(myLib)=='undefined'){setTimeout("initMyLib()",50);}else{useMyLib();}}moreStaffHappens();initMyLib();//->initMyLibisundefined})(this,documen

javascript - `new Function("在立即调用的函数中返回 this")()` 的目的是什么

我正在查看setImmediatepolyfill它包含在立即调用函数中,包含以下内容:(function(global,undefined){"usestrict";...}(newFunction("returnthis")()));我对最后一条语句的目的和传递给函数的参数感到困惑。这段代码既可以在浏览器中运行,也可以在Node.js上运行,这与它有什么关系吗?你能解释一下吗? 最佳答案 代码的编写使其可以访问全局范围,无需知道包含该范围的对象是什么。例如,在浏览器中,全局范围是window,但在其他容器中并非如此。通过使用Fu

javascript - 对象内部的匿名函数

我有一个像这样的Javascript片段:vara={ac:10,function(){console.log("hi")}}浏览器不会为此抛出错误。所以它可能是有效的。但是当我使用vara={ac:10,functionhi(){console.log("hi")}}浏览器抛出错误:UncaughtSyntaxError:Unexpectedidentifier谁能告诉我如何在Javascript的任何场景中使用第一个代码提前致谢 最佳答案 这里发生的事情是ES6允许你有一个shorthandsyntax用于函数定义。这个:con

javascript - Google Maps Uncaught TypeError : b. has is not a function

我们使用以下代码将GoogleMapsAPIV3包含在我们的内部系统中:脚本src="https://maps.googleapis.com/maps/api/js?key=&libraries=places,geometry"这在几个小时前(澳大利亚东部标准时间上午9点)之前一直有效,现在在控制台中返回的所有内容是:未捕获类型错误:b.has不是函数来自https://maps.googleapis.com/maps-api-v3/api/js/35/3/map.js有没有人遇到同样的问题?如果包含来自Google服务器的代码,我该如何解决? 最佳答案