I’ve got a JavaScript object similar to this:
var profile1 = {
one: "1",
two: "2"
}
var profile2 = {
one: "3",
two: "4"
}
function runLoop () {
console.log(this.one);
}
profile1.loop = runLoop;
profile2.loop = runLoop;
profile1.loop();
So profile1.loop() will run fine in this case and return a string value of "1". But if I try to run it from the console in either Chrome or Firefox, "1" will still return, but then send out a message of "undefined".
Can this be fixed or am I chasing my tail here?
I’d say you’re chasing your tail in that there’s nothing to fix. If you don’t want to see the word ‘undefined’ in the console, you could return anything from that function that you want to see.
e.g.