partial的强大不仅仅是预定义第0-n个入参的值,还可以分阶段预定义,如果用oo来说 就是一个多态(?)
原例子地址:http://dojotoolkit.org/reference-guide/dojo/partial.html
监听按钮click事件的时候分别使用handler1和handler2有2种截然不同的结果
这个核心函数用js重写也是非常赞的一个尝试
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html dir="ltr">
<head>
<style type="text/css">
body, html { font-family:helvetica,arial,sans-serif; font-size:90%; }
</style>
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dojo/dojo.xd.js"
djConfig="parseOnLoad: true">
</script>
<script type="text/javascript">
dojo.require("dijit.form.Button");
dojo.addOnLoad(function() {
var myClick = function(firstValue, secondValue, event) {
var node = dojo.byId("appendLocation");
node.appendChild(document.createTextNode(firstValue));
node.appendChild(document.createElement("br"));
node.appendChild(document.createTextNode(secondValue));
node.appendChild(document.createElement('br'));
}
var handler1 = dojo.partial(myClick, 'This is first text');
var handler2 = dojo.partial(handler1, 'This is second text');
dojo.connect(dijit.byId("myButton"), "onClick", handler2);
});
</script>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/dojo/1.5/dijit/themes/claro/claro.css"
/>
</head>
<body class=" claro ">
<button dojoType="dijit.form.Button" id="myButton">
Click me to append in a preset value!
</button>
<div id="appendLocation">
</div>
<!-- NOTE: the following script tag is not intended for usage in real
world!! it is part of the CodeGlass and you should just remove it when
you use the code -->
<script type="text/javascript">
dojo.addOnLoad(function() {
if (document.pub) {
document.pub();
}
});
</script>
</body>
</html>