码迷,mamicode.com
首页 > Web开发 > 详细

JS 代理模式

时间:2016-06-07 12:40:12      阅读:191      评论:0      收藏:0      [点我收藏+]

标签:

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<script>
			/*-------代理模式,A想执行C方法,A调用B间接执行*/
			function peopleSing() {
				this.singSong = function() {
					var songName = new peopleManageSongs().getSongName();
					alert("老子拿到歌了,你妈~~" + songName);
				};
			};

			function peopleManageSongs() {}
			peopleManageSongs.prototype.getSongName = function() {
				var name = new SongsCreator().getSongName(‘001‘);
				return name;
			}

			function SongsCreator() {
				this.getSongName = function(number) {
					switch (number) {
						case ‘001‘:
							return "独家记忆";
						case ‘002‘:
							return "空白格";
						case "003":
							return "蓝蓝的天上白云飘";
						default:
							return "我的心好累";
					}
				}
				this.getVipSongsName = function() {
					return "这是VIP的歌";
				}
			}
			var  p = new peopleSing().singSong();
		</script>
	</head>

	<body>
	</body>

</html>

  

JS 代理模式

标签:

原文地址:http://www.cnblogs.com/yqlog/p/5566479.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!