Timeline for answer to Auto call function within Object once object is called? by T.J. Crowder
Current License: CC BY-SA 4.0
Post Revisions
10 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 23, 2020 at 14:18 | comment | added | T.J. Crowder | @ETHan - Again, to help further I need to see a minimal reproducible example of the problem. Using a traditional function on the option object works just fine -- see the update at the end of the answer above. | |
| Jun 23, 2020 at 14:18 | history | edited | T.J. Crowder | CC BY-SA 4.0 |
added 2147 characters in body
|
| Jun 23, 2020 at 13:50 | comment | added | ETHan |
Yes I did that and I am still not getting the function to run. run: function run(){ this.logic();}
|
|
| Jun 23, 2020 at 9:02 | comment | added | T.J. Crowder |
@ETHan - Make run a traditional function like logic is, not an arrow function. Arrow functions close over this, but you want the traditional behavior of this being set by how the function is called. More details in the answers to this question.
|
|
| Jun 23, 2020 at 1:34 | comment | added | ETHan | I edited the post and added what I have been trying to do. | |
| Jun 22, 2020 at 22:09 | comment | added | T.J. Crowder |
@ETHan - No, not a jsFiddle. Put the code necessary to answer the question in the question, not just linked. But run: this.logic() calls this.logic() an assigns the result to the run property, just like foo: 42 assigns 42 to the foo property. If you meant that to be a function, you have to create a function: run: function() { this.logic(); }.
|
|
| Jun 22, 2020 at 18:12 | comment | added | ETHan |
I am defining logic here logic: function update() { console.log("update function worked") and then adding another key pair to that option like run: this.logic() and that doesn’t work. Let me send a JS fiddle for you to see.
|
|
| Jun 22, 2020 at 16:01 | comment | added | T.J. Crowder |
@ETHan - To help further, I need a minimal reproducible example of the problem showing not just where/how logic is defined, but also where/how the function you want to call it from is defined. If it were on the option like logic is, this.logic(); would work.
|
|
| Jun 22, 2020 at 15:43 | comment | added | ETHan |
thank you for the response T.J. However, I am a little confused here. I tried adding a key to my option called runFunction: logic(), but I get the error that logic does not exist. I also tried this.logic and that also didn't work. Is there a way to do this ( not the way you show after you say "if for some reason you don't want to do that", but just adding the function call at the end ).
|
|
| Jun 22, 2020 at 14:05 | history | answered | T.J. Crowder | CC BY-SA 4.0 |