Calling a method from within itself is not working

Dshiz

I am trying to call a method again from within itself after a period of time, but it isn't working.

I have the the following:

Hi.prototype.stuff = function(){
    console.log("hello")
    setTimeout(()=>this.stuff(), 1000)
}

However, it outputs "hello" to the console only once. It should output "hello" twice. Is there a way to do this?

blex

Did you declare and instanciate Hi correctly? This seems to work:

function Hi(name) {
  this.name = name;
}

Hi.prototype.stuff = function() {
  console.log(`Hello ${this.name}`);
  setTimeout(() => this.stuff(), 1000);
};

const x = new Hi('Dshiz');
x.stuff();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Calling method within itself

From Dev

Calling a function from within itself in C#

From Dev

python - calling a function from within itself

From Dev

Calling a singleton method within an instance method in a module that extends itself

From Dev

C# Syntax around calling method within itself

From Java

Calling a method on an Object from within a Class vs from within a method

From Dev

Calling a constructor from method within the same class

From Java

Calling super method from within super class

From Dev

calling an object method from another method not working

From Dev

Calling a React component within itself

From Dev

Calling a method from superclass not working Java

From Dev

Calling a method from ABL code not working

From Dev

Minitest - calling a mocked instance method from within another instance method

From Dev

Grails / Spock: How to mock single method within class where method is called from within the class itself?

From Java

Calling a method from a class from an element within a list of Objects

From Dev

PHP Calling function within itself bricks

From Dev

Calling a method within another method

From Dev

Calling a method within the same method?

From Dev

Bash script loop ends prematurely when recursively calling itself from within

From Dev

Calling a static Swift Method from within Obj-C

From Dev

PHP Calling a callback function from within Object method

From Dev

calling an object method with a setTimeout function from within the same object in Javascript

From Java

Calling one method from another within same class in Python

From Java

Calling parent method from within a Thread having the same name

From Dev

Calling custom method from within a Ruby core class

From Dev

Object with 2 methods. Method A, Method B. Calling Method B from within Method A

From Dev

Call model from within itself

From Java

Recursively calling an object method that returns an iterator of itself

From Dev

Method when called virtually calling itself recursively

Related Related

  1. 1

    Calling method within itself

  2. 2

    Calling a function from within itself in C#

  3. 3

    python - calling a function from within itself

  4. 4

    Calling a singleton method within an instance method in a module that extends itself

  5. 5

    C# Syntax around calling method within itself

  6. 6

    Calling a method on an Object from within a Class vs from within a method

  7. 7

    Calling a constructor from method within the same class

  8. 8

    Calling super method from within super class

  9. 9

    calling an object method from another method not working

  10. 10

    Calling a React component within itself

  11. 11

    Calling a method from superclass not working Java

  12. 12

    Calling a method from ABL code not working

  13. 13

    Minitest - calling a mocked instance method from within another instance method

  14. 14

    Grails / Spock: How to mock single method within class where method is called from within the class itself?

  15. 15

    Calling a method from a class from an element within a list of Objects

  16. 16

    PHP Calling function within itself bricks

  17. 17

    Calling a method within another method

  18. 18

    Calling a method within the same method?

  19. 19

    Bash script loop ends prematurely when recursively calling itself from within

  20. 20

    Calling a static Swift Method from within Obj-C

  21. 21

    PHP Calling a callback function from within Object method

  22. 22

    calling an object method with a setTimeout function from within the same object in Javascript

  23. 23

    Calling one method from another within same class in Python

  24. 24

    Calling parent method from within a Thread having the same name

  25. 25

    Calling custom method from within a Ruby core class

  26. 26

    Object with 2 methods. Method A, Method B. Calling Method B from within Method A

  27. 27

    Call model from within itself

  28. 28

    Recursively calling an object method that returns an iterator of itself

  29. 29

    Method when called virtually calling itself recursively

HotTag

Archive