jjzjj

function-prototypes

全部标签

javascript - 为什么不应该向 JavaScript 构造函数添加功能,而是通过原型(prototype)添加功能?

我在看AddyOsmani关于构造函数模式的章节:http://addyosmani.com/resources/essentialjsdesignpatterns/book/#constructorpatternjavascript我遇到了以下情况:functionCar(model,year,miles){this.model=model;this.year=year;this.miles=miles;this.toString=function(){returnthis.model+"hasdone"+this.miles+"miles";};}//Usage://Wecancr

javascript - AngularJS: "TypeError: undefined is not a function"与 routeProvider

我正在尝试追踪AngularJS中的“TypeError:undefinedisnotafunction”错误。如果您有任何想法,甚至更好,关于如何调试此类内容的建议,我将不胜感激。请注意,这与我正在处理的代码非常相似,但并不完全相同(尽管它在运行时仍然有相同的错误)。追踪:TypeError:undefinedisnotafunctionatupdate(http://localhost:63342/Channels/vendor/angular-route.js:838:13)atScope.$broadcast(http://localhost:63342/Channels/ve

javascript - 类型错误 : undefined is not a function in Angular Resource

当尝试在AngularJS资源上轮询自定义方法copies时,我在angular.js:10033处收到以下错误:(方法copy工作得很好。)TypeError:undefinedisnotafunctionathttps://code.angularjs.org/1.3.0-beta.8/angular-resource.min.js:9:347atArray.forEach(native)atq(https://code.angularjs.org/1.3.0-beta.8/angular.min.js:7:280)atq.then.p.$resolved(https://code

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:函数.原型(prototype).方法

我想你们中的大多数人都看过以下代码片段:Function.prototype.method=function(name,func){this.prototype[name]=func;returnthis;};我也知道它会影响所有函数,因为它们都是由Function创建的对象,因此它们可以访问名为“method”的方法,但是我很困惑为什么Function本身也可以像下面这样访问“method”:Function.method('test',function(){return1;}); 最佳答案 Edorka的回答是正确的:函数是它自

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 - 如何在 JavaScript 中为 Number.toFixed 编写原型(prototype)?

我需要使用JavaScript将小数四舍五入到六位,但我需要考虑旧版浏览器,所以我can'trelyonNumber.toFixedThebigcatchwithtoExponential,toFixed,andtoPrecisionisthattheyarefairlymodernconstructsnotsupportedinMozillauntilFirefoxversion1.5(althoughIEsupportedthemethodssinceversion5.5).Whileit'smostlysafetousethesemethods,olderbrowsersWILL

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()无济于事。如果有人能阐明一些问题,我将不胜感激。谢谢。 最佳答案 啊,再看一遍,我觉得报错信息大