callback呼び出しテスト

7793 ワード

<html>

<head>

<script>    

    var context=" ";

    var testObj={        

        context:" ",

        callback:function (str){// 

            alert("callback: ,context="+this.context+", :"+str);

        },

        caller:function(){            

            callWithClosure(function(param){this.callback(param);});

            var temp=this;

            callWithClosure(function(param){temp.callback(param);});            

        } 

    };//

    testObj.context=" ";

    

    function testCall(){                    

        callMethod(testObj.callback);

        testObj.caller();

        callWithClosure(function(param){testObj.callback(param);});

        callObjMethod(testObj,testObj.callback);        

    } 

    function callObjMethod(obj,method){        

        method.call(obj," ");

    }

    function callMethod(method){        

        method(" ");        

    }

    function callWithClosure(method){        

        method(" Closure ");        

    }

    

    function callback(str){

        alert("callback: 。");

    }

</script>

</head>

<body>

<a href="javascript:void(0)" onclick="testCall()"> </a>

</body>

</html>