0

I see several questions about callbacks: obviously, there is no callback involved here, and I'm struggling to see the relevance of any of the previous answers. I don't doubt that there is some relevance, just that none of the previous answers explain or demonstrate that relevance.

To be clear: I don't know how renaming a function by using a procedural variable changes context. That would be obvious if I was implementing a callback, but I'm not: I've not moved to the call to a different object by using a callback, and I don't know what the new context is, or how or why it changed.

I've got a function:

export default class Popup {
  shower(label, value, valueList, saveEvent) {
    let classInstance = this;
    let domObjects = [ classInstance.dom.text(label, "p") ];
  }
}

Which is called like this:

export default class Controller {
  constructor(model, view) {
    this.model = model;
    this.view = view;
  }

function fred(void){
    fn=this.view.popup.shower;
    fn(label, stat.value, lst, myOtherfn); 

}

..But that doesn't work. If fails because, when called that way, there is something undefined about

classInstance.dom.text(label, "p") 

(when called from the exact same place as a normal call, it works correctly)

function fred(void){
    this.view.popup.shower(label, stat.value, lst, myOtherfn); 
}

I don't know enough about javascript even to be dangerous. What does dom.text("mytext" , "p") mean? Apparently I get a different this.dom from the two call methods? And how can I use a variable procedure in a way that doesn't mess with context?

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
david
  • 2,435
  • 1
  • 21
  • 33
  • `this` is called the "context", not "scope" – Bergi Jun 02 '23 at 03:49
  • @Bergi thanks. At least learned one thing :) I've corrected the quesion. However, it looks like I won't be able to ask the question anyway. – david Jun 02 '23 at 04:04

0 Answers0