![](/img/trans.png)
[英]How to pass arguments from a javascript function to another function without calling it?
[英]How to pass javascript function into another function without predefining?
我在angularJS
有这样的东西:
var onErr = function() {};
var sent = httpService.handleRequest(onErr);
我想传递函数而不在另一行中定义。 因为有许多函数什么都不返回。
我的意思是这样的:
// no definition
var sent = httpService.handleRequest(new function1, new function2);
您可以内联创建函数:
var sent = httpService.handleRequest(function () {}, function () {});
虽然我不清楚您传递的函数的返回值与为什么要声明内联而不是预先声明它们有什么关系?
您可以使用没有操作功能的原始概念。
var nop = function() {};
var sent = httpService.handleRequest(nop, nop);
您可以使用匿名函数。
var sent = httpService.handleRequest(function() {}, function() {});
匿名函数是没有名称的函数,可以用作另一个函数的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.