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?
RPCcannot tell how its return value is used, the syntax is not possible. You're trying to use JavaScript in ways it cannot be used. Additionally, ifRPCuses AJAX to fetch a value, the value will not even be available to return. You will have to either return a promise or pass a callback function intoRPC.