js原生之一个面向对象的应用
function IElectricalEquipment() {
}
IElectricalEquipment.prototype = {
poweron: function () {
},
poweroff: function () {
}
};
function Fan(){//电风扇
}
Fan.prototype=new IElectricalEquipment;
Fan.prototype.poweron=function(){
console.log("Fan'power on")
};
Fan.prototype.poweroff=function(){
console.log("Fan'power off")
};
function Light(){//电灯
}
Light.prototype=new IElectricalEquipment;
Light.prototype.poweron=function(){
console.log("Light'power on")
};
Light.prototype.poweroff=function(){
console.log("Light'power off")
};
var createSwitch=(function () {
function Switch(){
this.equipment=null;
}
Switch.prototype={
on:function(){
this.equipment.poweron();
},
off:function(){
this.equipment.poweroff();
}
};
return function(){
return new Switch();
}
}());
var myLight=new Light();
var myFan=new Fan();
var FanSwitch=createSwitch();
FanSwitch.equipment=myFan;
FanSwitch.on();
FanSwitch.off();
FanSwitch.equipment=myLight;
FanSwitch.on();
FanSwitch.off();
js原生之一个面向对象的应用的更多相关文章
- js原生实现轮播图效果(面向对象编程)
面向对象编程js原生实现轮播图效果 1.先看效果图 2.需要实现的功能: 自动轮播 点击左右箭头按钮无缝轮播 点击数字按钮切换图片 分析:如何实现无缝轮播? 在一个固定大小的相框里有一个ul标签,其长 ...
- 15、js 原生基础总结
Day1 一.什么是JS? ==基于对象==和==事件驱动==的客户端脚本语言 二.哪一年?哪个公司?谁?第一个名字是什么? 1995,NetScape(网景公司),布兰登(Brendan Eic ...
- js原生代码实现轮播图案例
一.轮播图是现在网站网页上最常见的效果之一,对于轮播图的功能,要求不同,效果也不同! 我们见过很多通过不同的方式,实现这一效果,但是有很多比较麻烦,而且不容易理解,兼容性也不好. 在这里分享一下,用j ...
- JS原生效果瀑布流布局的实现(一)
JS原生效果 实现: HTML页面布局: <!DOCTYPE html> <html> <head> <meta charset="utf-8&qu ...
- 工作当中实际运用(3)——js原生实现鼠标点击弹出div层 在点击隐藏
function onmou(){ var divs=document.getElementById('kefuDV');//获取到你要操作的div if (divs.style.display==& ...
- 仿jQuery的siblings效果的js原生代码
仿jQuery的siblings效果的js原生代码 <previousSibling> 属性返回选定节点的上一个同级节点(在相同树层级中的前一个节点). <nextSibling&g ...
- js原生的url操作函数,及使用方法。(附:下边还有jquery对url里的中文解码函数)
js原生的url操作函数,完善的. /*****************************/ /* 动态修改url */ /*****************************/ var ...
- 图片轮播(左右切换)--JS原生和jQuery实现
图片轮播(左右切换)--js原生和jquery实现 左右切换的做法基本步骤跟 上一篇文章 淡入淡出 类似,只不过修改了一些特定的部分 (1)首先是页面的结构部分 对于我这种左右切换式 1.首先是个外 ...
- 图片轮播(淡入淡出)--JS原生和jQuery实现
图片轮播(淡入淡出)--js原生和jquery实现 图片轮播有很多种方式,这里采用其中的 淡入淡出形式 js原生和jQuery都可以实现,jquery因为封装了很多用法,所以用起来就简单许多,转换成j ...
随机推荐
- js选择一个选项 跳出另一个选项 跳出一个输入框
跳出输入框 <script language="javascript"> function $(obj){return document.getElementById( ...
- Linux Mint 17.2个性化配置
一.开启root 帐号登陆 设置一个口令,使用: sudo passwd root 当你使用完毕后屏蔽root帐号使用以下命令锁定root帐号 : sudo passwd -l root 如何在终端模 ...
- XML字符串解析成对象的时候应注意空格
BomList bomList=(BomList)unmarshaller_bom.unmarshal(new StringReader(xml));xml 不能以空格开头
- margin问题
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- Permission denied: user=xxj, access=WRITE, inode="user":hadoop:supergroup:rwxr-xr-x
在windows中运行eclipse时报错Permission denied: user=xxj, access=WRITE, inode="user":hadoop:superg ...
- A. Round House
A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard input ...
- 计算机学院大学生程序设计竞赛(2015’12) 1004 Happy Value
#include<cstdio> #include<cstring> #include<cmath> #include<vector> #include ...
- Lua打印Table的数据结构工具类
--这是quick中的工具,作用就是打印Lua中强大的table的结构, 当table的嵌套层级比较多的时候,这个工具非常方便,开发中必备的工具. --具体使用方法:local debug = req ...
- openstack controller ha测试环境搭建记录(三)——配置haproxy
haproxy.cfg请备份再编辑:# vi /etc/haproxy/haproxy.cfg global chroot /var/lib/haproxy daemon group ...
- [Programming WCF Services]Chapter 1. WCF Essentials - EndPoint
1.配置文件方式设置EndPoint(ABC) 1.1.基本配置 <system.serviceModel> <services> <service name=" ...