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 ...
随机推荐
- ural1542 Autocompletion
Autocompletion Time limit: 2.0 secondMemory limit: 64 MB The Japanese are infinitely in love with ma ...
- android 手势识别学习
引自http://www.cnblogs.com/android100/p/android-hand.html http://blog.csdn.net/jiangshide/article/d ...
- JAVA Timer定时器使用方法(二)
JAVA Timer 定时器测试 MyTask.java:package com.timer; import java.text.SimpleDateFormat;import java.util. ...
- apk文件分析原则
如果在dex生成的jar文件里没有发现关键内容的话,就要注意jar里面的native函数以及loadlibrary操作,从而可以判断出加载了哪些so,调用了什么函数.就不会出现判断不出是不是加载了某s ...
- Android 之 ServiceManager与服务管理
ServiceMananger是android中比较重要的一个进程,它是在init进程启动之后启动,从名字上就可以看出来它是用来管理系统中的service.比如:InputMethodService. ...
- armstrong's programming erlang 2nd
Re: json handling map functions in erlang 17 I have not read Joes final book on the matter (several ...
- 2快速掌握OMD
我们已经知道使用ArcGIS Engine开发,也就意味着我们要和接口打交道,ArcGIS Engine中提供的接口和类加起来估计上万,但是用过ArcGIS Engine的人,知道这个数字不为过.Ar ...
- html中DIv并排显示问题
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD ...
- NOIP2016DAY1题解
https://www.luogu.org/problem/lists?name=&orderitem=pid&tag=33%2C83 T1:玩具谜题 题解: 沙茶模拟 #includ ...
- Identifying Dialogue Act Type
Natural Language Processing with Python Chapter 6.2 import nltk from nltk.corpus import nps_chat as ...