Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    how call an inner function in javascript

    i have an inner function and i call it with setTimeout like this :
    Code:
    <!DOCTYPE html>
    
    <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta charset="utf-8" />
        <title></title>
        <script type="text/javascript">
    
            function Overrideablefunc() {
    
                this.runfunc=function () {
                    document.getElementById('txt').value = Date().substring(0, 24);
                    //***************************************
                    var overrd = new Overrideablefunc()
                    setTimeout(overrd.runfunc, 1000);
                    //***************************************
    
                 }
            }
    
            function runnewfunc() {
                var a=new Overrideablefunc()
                a.runfunc();
            }
    
        </script>
    
    </head>
    <body>
        <input type="button" value="Run" onclick="runnewfunc()"/><br />
        <input type="text" id="txt" style="width:400px"/>
    </body>
    </html>
    i call my function with

    //***************************************
    var overrd = new Overrideablefunc()
    setTimeout(overrd.runfunc, 1000);
    //***************************************

    but i don't know this way is right or not?
    do i have any other way for call my function?
    thank you

  • #2
    New to the CF scene
    Join Date
    Dec 2012
    Location
    Viet Nam
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    1. I think to upper case with setTimeOut . you can tried it .
    2. why do you direct call funtion Overrideablefunc in button and have one solution , you can create function(ready){
    in here . you can call any funtion js come it }

  • #3
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    You shouldn't create an instance of the object inside the object itself
    Code:
            function Overrideablefunc() {
    
                this.runfunc=function () {
                    document.getElementById('txt').value = Date().substring(0, 24);
                 }
            }
    
            function runnewfunc() {
                var a=new Overrideablefunc()
                setInterval(a.runfunc, 1000);
            }


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •