Click here to Skip to main content
Rate this: bad
good
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 4:13am
Comments
Sergey Alexandrovich Kryukov at 13-Mar-13 1:48am
   
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 at 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
0 Peter Leow 395
1 Sergey Alexandrovich Kryukov 350
2 Zoltán Zörgő 258
3 CHill60 195
4 CPallini 165
0 Sergey Alexandrovich Kryukov 8,943
1 OriginalGriff 6,631
2 Peter Leow 4,102
3 Zoltán Zörgő 3,714
4 Kornfeld Eliyahu Peter 2,525


Advertise | Privacy | Mobile
Web01 | 2.8.150123.1 | Last Updated 10 Dec 2012
Copyright © CodeProject, 1999-2015
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