![](/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.