dojo/hitch/partial

http://dojotoolkit.org/documentation/tutorials/1.9/hitch/ 英文原文

http://blog.csdn.net/dojotoolkit/article/details/7612989 中文翻译

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
    <title></title>
    <style type="text/css">
        .myNodes{display:inline;background-color: #1e90ff;}
    </style>
    <script src="dojo-release-1.9.1\dojo\dojo.js" data-dojo-config="async:true"></script>
    <script>
        require(["dojo/query","dojo/_base/lang", "dojo/domReady!"],
                function(query,lang) {

                    var myObject = {
                        foo: "bar",
                        myHandler: function(evt){
                            //  this is very contrived but will do.
                            alert("The value of 'foo' is " + this.foo);
                        }
                    };

                    //  later on in the script:
                    /*query(".myNodes").forEach(function(node){
                        //node.onclick = myObject.myHandler;   undefined
                    });*/

                    query(".myNodes").forEach(function(node){
                        node.onclick =lang.hitch(myObject, myObject.myHandler);

                    });

                });
    </script>
</head>
<body>
<div class="myNodes">第一个</div>
<div class="myNodes">第二个</div>
<div class="myNodes">第三个</div>
</body>
</html>

 

posted @ 2014-02-19 15:45  刘朝样  阅读(142)  评论(0)    收藏  举报