Click here to Skip to main content
15,501,490 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi i have a inner function and i call its with setTimeout.but It will not run.
what's my wrong
thank you

my code is :
JavaScript
<!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);
                setTimeout(this.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>
Posted
Comments
Sergey Alexandrovich Kryukov 13-Mar-13 1:48am     CRLF
Please don't post non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership. Comment on any posts, reply to available comments, or use "Improve question" (above). Also, keep in mind that members only get notifications on the post sent in reply to there posts. —SA

1 solution

Overrideablefunc now acts like an object, you have to create an instance of it and then you can call runfunc

JavaScript
var override = new Overrideablefunc();
override.runfunc();
 
Share this answer
 
Comments
Sina asefi 10-Dec-12 11:21am     CRLF
first thank you for your response is it mean i should call my function with : var overrd = new Overrideablefunc() setTimeout(overrd.runfunc, 1000); thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900