草庐IT

private-functions

全部标签

javascript - react .js : onClick function from child to parent

我用了this以文章为例(React方式),但它对我不起作用。请指出我的错误,因为我不明白哪里出了问题。这是我看到的错误:UncaughtTypeError:this.props.onClickisnotafunction这是我的代码://PARENTvarSendDocModal=React.createClass({getInitialState:function(){return{tagList:[]};},render:function(){return({this.state.tagList.map(function(item){return()})})},HandleRem

javascript - 在对显示模块进行单元测试时如何 stub 私有(private)函数

我一直在构建一个Node模块,它包装了对GitHubAPI的大量调用,并且以我无限的智慧使用揭示模块模式构建了这个模块,使我的包装函数保持私有(private)并且只公开简单的方法。请参见下面的示例:github.shortcuts=(function(){varappPath;varcreateRepo=function(name){vardeferred=Q.defer();github.repos.create({name:name,auto_init:true},function(error,result){if(error){deferred.reject(newError(

javascript - 在 Firebase 云函数中包含异步函数 (eslint "Parsing error: Unexpected token function")

问题如何将async辅助方法添加到CloudFunctionsindex.js文件中?在将fs.writefile转换为Promise时,需要一个async函数才能使用await,如本文所述StackOverflow帖子:fs.writeFileinapromise,asynchronous-synchronousstuff.但是,lint不赞成在exports函数之外向index.js文件添加额外的方法。错误第84行引用辅助函数asyncfunctionwriteFile。Users/adamhurwitz/coinverse/coinverse-cloud-functions/fu

functional-programming - 是否有一个JavaScript库向Array添加缺少的标准迭代方法(过滤器,映射,减少,某些…)?

是否有一个javascript库,它只是添加了一些已经标准化的数组、对象和其他标准对象的方法,但并不是所有浏览器都可以使用这些方法?我在想Array中的iterationmethods,比如filter()、map()、reduce()、some()或keys()中的Object。请注意,我不希望库引入任何花哨的东西;如果当前浏览器中还没有实现“标准”方法,则只引入它们。 最佳答案 我相信你在找Underscore.js。http://documentcloud.github.com/underscore/

私有(private)属性的 Javascript 动态 getter/setter

我想动态地创建getter/setter方法来检索私有(private)属性。这是我做的。首先,我制作了这个类:functionwinClass(posX,posY,w,h){varx=posX||0;vary=posY||0;varwidth=w||0;varheight=h||0;}然后我用getter/setter方法扩展了winClass,如下:winClass.prototype.getX=function(){returnx;}winClass.prototype.setX=function(val){x=val;}然后我测试了:varwin1=newwinClass(10

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 - Mootools 类中的私有(private)方法

我对在Javascript中使用oop比较陌生,我想知道私有(private)方法的最佳实践是什么。现在,我正在使用mootools创建我的类,并通过在私有(private)方法前加上下划线并强制自己不要在类外部调用该方法来模拟私有(private)方法。所以我的课看起来像:varNotifier=newClass({...showMessage:function(message){//publicmethod...},_setElementClass:function(class){//privatemethod...}});这是在JS中处理私有(private)方法的良好/标准方式

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