There are many JavaScript functions out there that accept an object directly here are some examples. This is isn’t specific to either of these functions jquery’s $.ajax() or the nodejs module request(), both are just examples.
$.ajax({
method: "post",
data: {'hello':'world'},
})
request({
method : "post",
body : "hello world",
});
I just tried something that I thought would work and it was a more elaborate version of this.
request({
method : function(){
return "post";
},
data: {'hello':'world'},
});
To my surprise it didn’t work. Neither does this.
var m = function(){
return "post";
};
request({
method : m,
data: {'hello':'world'},
});
Am I missing something? Is there some way to get a generated function into these objects? I’d love some feedback.
You don’t want to pass a function here, you want to pass its return value.