Click here to Skip to main content
12,357,063 members (69,685 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: Javascript
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 :
<!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 10-Dec-12 3:13am
Comments
   
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

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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

var override = new Overrideablefunc();
override.runfunc();
  Permalink  
Comments
Sina asefi 10-Dec-12 11:21am
   
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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160621.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100