Wednesday, December 19, 2012

javascript sync callback

js syncronise callback example :

<html>
    <head>
        <title>Haghe ostadi</title>
    </head>
    <body>

        <script language="javascript">
            function before(){
                this.call=function call(){
                    alert('call back!!');
                }
               
                after(this);
                alert('this would have been called first if it was async');
            }
            function after(x){
                for (i=0; i<100000000;i++){
                    var t= 'x2'=='x1';
                }
                x.call();
            }
            document.load=before();
        </script>

    </body>
</html>