0

Since I'm passing a function to another class method as a callback, I need to apply my function's this value as itself. I know there is some way using bind,call,apply but I want to set function's "this" value inside the function. Is there any way?

function CallBack(){
    this.setValue(...whatever);
    this.somekindofMethods(...whatever);
    !!Can I set "this" inside the function??
}
  • 2
    "_Can I set "this" inside the function?_" No, you can't, `this` value is defined when a function is called. – Teemu Jun 02 '22 at 07:09
  • 3
    Variables names starting with capital letters are, in idiomatic JavaScript, reserved for constructor functions and classes. Don't use that naming convention for a regular function. – Quentin Jun 02 '22 at 07:10
  • you mentioned [bind](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind), take another look at that. – Thomas Jun 02 '22 at 07:14

0 Answers0