-4

私はthisjavascriptでどのように機能するかを理解することに取り組んでおり、チュートリアルでこの例に出くわしました。この例では構文エラーが発生するため、誰かがエラーの原因を説明できることを願っています。コード:

 <!DOCTYPE html><html lang="en">
        <body>
            <script>
                var myObject = {
                   myProperty:'Icanseethelight',
                   myMethod:function() {
                       var that=this; 
                       var helperFunctionfunction(){
                            function() { 
                                console.log(that.myProperty);
                                console.log(this);
                            }();
                    }
                }

                myObject.myMethod(); // invoke myMethod

        </script>
    </body>
</html>
4

2 に答える 2

1
var myObject = {
    myProperty:'Icanseethelight',
    myMethod:function() {
       var that=this; 
       var helperFunction = function(){
           console.log(that.myProperty);
           console.log(this);
       }
    }
}
myObject.myMethod();
于 2012-10-16T07:40:44.213 に答える
0

helperFunctionfunction(){ varを次のように置き換える必要がありますvar helperFunction = function(){

于 2012-10-16T07:39:30.530 に答える