Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8377479
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:40:52+00:00 2026-06-09T15:40:52+00:00

Here is the code. (function($){ $.fn.testfunc = function() { this.init = function() { setInterval(this.func1(),

  • 0

Here is the code.


(function($){
    $.fn.testfunc = function() {

        this.init = function() {
            setInterval(this.func1(), 1000);
        };

        this.func1 = function() {
            console.log('func1');
            this.func2();
        };

        this.func2 = function() {
            console.log('func2');
            //some codes
        };

        return this.init();
    }
})(jQuery);

*When I use parenthesis the 1st and 2nd method runs but the 1st method is called only once.

*When I don’t use parenthesis the 1st method runs in interval just fine but it doesn’t/couldn’t call the 2nd method.

What should I go with? With parenthesis or not? I need to run the 1st method in the interval but also need to call 2nd method.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:40:53+00:00Added an answer on June 9, 2026 at 3:40 pm

    setInterval expects a function. this.func1 is a function but this.func1() is the result of calling the function, which is undefined (the function doesn’t return anything). This is your first misunderstanding.

    The second misunderstanding has to do with scope. If you call setInterval(this.func1, 1000); then setInterval will call the correct function, but this will not refer to what you think. I don’t have time now to explain and you should definitely read more about this. In any case, this will work:

    this.init = function() {
        var self = this;
        setInterval(function() { self.func1(); }, 1000);
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code: function myChmod($path, $permission, $log) { //this is to overcome umask
Here is my code: function currentCursPos(){ $(document).mousemove(function(e){ var pos= {"x":e.pageX,"y":e.pageY}; return pos }); }
Here is the code in a function I'm trying to revise. This example works
here my code- create function dbo.emptable() returns Table as return (select id, name, salary
Here's my code: function mouseOver(variable) { return function() { $(variable).fadeIn(100); }; } function mouseOut(variable)
Here is the code: function change_case($str, $type) { return str'.$type.'($str); } change_case('String', 'tolower'); It
Hi i have problem with some things Here is the code function get_char_val(merk) {
Here's my code: function admin_delete($id = null){ $booking = $this->Booking->read(null, $id); if($this->Booking->delete($id)) { $this->Session->setFlash('Booking
So I have found this code here This basically lets me pull some data
I'm using this technique to restart the game. Here is the code: function restart(e:MouseEvent)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.