Maximilian
Lifer
Code:
var serverAPI = {
port:8080,
frontController:"FrontController",
mainURL:function(){return "localhost:"+this.port+"/"+this.frontController+"/";}
};
//this prints "localhost:8080/FrontController/" to console
console.log(serverAPI["mainURL"]());
//this prints "localhost:undefined/undefined/" to console
var aFunction = serverAPI["mainURL"];
console.log(aFunction());
I was going to ask why this happens... they should print out the same thing to console. I just came up with a theory though.
Is it because when I fetch the function and store it as "aFunction" then the "this" keyword no longer has the same scope it did before? So it cant access port or frontController. Is that whats happening here?