面向对象编程-状态模式(js)
来源:互联网 发布:银河麒麟软件下载 编辑:程序博客网 时间:2024/06/05 12:07
面向对象编程-状态模式(js)
本文参考状态模式(js)
rainbow.prototype.init = function(){self = this;console.log(this);//<span style="color:#ff0000;">this1</span>this.button.onclick=function(){console.log(this);//<span style="color:#ff0000;">this2</span>self.currentColor.buttonPress.call(self);}};
var rainbow = function(){this.currentColor = COLOR.red;this.button = document.getElementsByClassName("circle")[0];};rainbow.prototype.init = function(c){self = this;this.button.onclick=function(){self.currentColor.buttonPress.call(self);}};var COLOR = {red:{buttonPress:function (){document.getElementsByClassName("circle")[0].style.backgroundColor = "orange";this.currentColor = COLOR.orange;}},orange:{buttonPress:function (){document.getElementsByClassName("circle")[0].style.backgroundColor = "yellow";this.currentColor = COLOR.yellow;}},yellow:{buttonPress:function (){document.getElementsByClassName("circle")[0].style.backgroundColor = "red";this.currentColor = COLOR.red;}}};new rainbow().init("circle");
<!DOCTYPE html><html><head><meta charset="UTF-8"><meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /><link rel="stylesheet" href="../css/style.css" /><title>状态模式</title><style>.circle{width:100px;height:100px;border-radius: 50%;background-color: red; margin: 100px auto;}</style></head><body><div class="return_nav"><div class="return_nav_img" onClick="javascript:window.location.href='../index.html'"></div>状态模式</div><div class="circle" ontouchend=""></div></body><script src="index.js"></script></html>
0 0
- 面向对象编程-状态模式(js)
- 面向对象编程思想-状态模式
- js 设计模式 oop 面向对象编程
- js 设计模式 oop 面向对象编程
- js 设计模式 oop 面向对象编程
- js面向对象混合模式编程
- js 面向对象编程
- js 面向对象编程
- js 面向对象编程
- JS面向对象编程
- js面向对象编程
- Js面向对象编程
- JS面向对象编程
- js面向对象编程
- js面向对象编程
- js面向对象编程
- js面向对象编程
- js面向对象编程
- wget下载百度网盘文件
- 代理模式(三):远程代理,虚拟代理,缓冲代理
- 制作iOS Ad-Hoc测试应用
- centos vsftp安装及配置
- 转载:Linux添加/删除用户和用户组
- 面向对象编程-状态模式(js)
- 我已率先抢占昵称,我的昵称独一无…
- iptables 打开dns访问端口
- Linux 双网卡NAT上网设置
- mining_proxy其实也有linux版本
- 37. GNUTS
- windows下配置nginx+php环境
- A卡速度表以及软件的设置参数(二…
- 很实用,A卡速度表以及软件的设置…