dojo.connect

    dojo的connect方法主要有两个作用:

    1.函数链式的调用

     当一个函数被调用,通过dojo.connect可以使另一个函数也被调用,像链条一样触发。

 

<!DOCTYPE HTML>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>Demo</title>
		<script src="dojo16/dojo/dojo.js"
		data-dojo-config="async: true, parseOnLoad: true,isDebug:true"></script>
		</link>
		<script type = "text/javascript">
			function Foo(){
				this.greet = function(){
					console.log("foo");
				}
			}
			
			function Bar(){
				this.greet = function(){
					console.log("bar");
				}
			}
			
			var foo = new Foo();//var foo = new Foo;
			var bar = new Bar();//var foo = new Bar;
			
			var handle = dojo.connect(foo,"greet", bar,"greet");
			foo.greet();
			dojo.disconnect(handle);
			
		</script>
	</head>
	<body>
	</body>
</html>

    2.DOM事件于处理函数的绑定

<!DOCTYPE HTML>
<html lang="en">
	<head>
		<meta charset="utf-8">
		<title>Demo</title>
		<script src="dojo16/dojo/dojo.js"
		data-dojo-config="async: true, parseOnLoad: true,isDebug:true"></script>
		</link>
		<script type = "text/javascript">
			function func(){
				dojo.connect(dojo.byId("test"),"onmouseover",function(evt){
					//console.log("testing...");
					alert("testing...");
				});
			}
			dojo.addOnLoad(func);
			
		</script>
	</head>
	<body>
		<div id = "test">hello</div>
	</body>
</html>
 

 

你可能感兴趣的:(connect)