Reputation: 13
I would like to know if it is possible to check if a function call is returning to a variable definition, or to the global scope.
function getName() {
if (!isVariableDefinition()) {
console.log("John Doe");
} else {
return "John Doe";
}
var name = getName()
// name == "John Doe"
getName()
// Should print "John Doe" to the console
I have code that calls for a remote procedure (via AJAX) from a server. At the server, if the procedure is a variable definition, it's name should be saved for other uses, if not, it should just return the results.
var result = RPC('getName')
// The server should receive "result" and the call
RPC('getName')
// The server should receive only the call
Is that syntax possible?
Upvotes: 1
Views: 53
Reputation: 239291
No, it's not possible. A function has no idea what is being done with the value it returns.
Upvotes: 4