JS 面向对象详解
面向对象详解1
OO1.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<script src="js/app1.js"></script>
</body>
</html>
js/app1.js
/*function People(){
}
People.prototype.say=function(){
alert("hello");
}
function Student(){
}
Student.prototype=new People();
var superSsay=Student.prototype.say;
Student.prototype.say=function(){
superSsay.call(this);
alert("stu-hello");
}
var s=new Student();
s.say();*/
/*function People(name){
this._name=name;
}
People.prototype.say=function(){
alert("peo-hello"+this._name);
}
function Student(name){
this._name=name;
}
Student.prototype=new People();
var superSsay=Student.prototype.say;
Student.prototype.say=function(){
superSsay.call(this);
alert("stu-hello"+this._name);
}
var s=new Student("iwen");
s.say();*/
(function(){
var n="ime";
function People(name){
this._name=name;
}
People.prototype.say=function(){
alert("peo-hello"+this._name);
}
window.People=People;
}());
(function(){
function Student(name){
this._name=name;
}
Student.prototype=new People();
var superSsay=Student.prototype.say;
Student.prototype.say=function(){
superSsay.call(this);
alert("stu-hello"+this._name);
}
window.Student=Student;
}());
var s=new Student("iwen");
s.say();
面向对象详解2
OO2.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script src="js/app2.js"></script>
</body>
</html>
js/app2.js
/*function Person(){
var _this={};
_this.sayHello=function(){
alert("P-hello");
}
return _this;
}
function Teacher(){
var _this=Person();
var surperSay=_this.sayHello;
_this.sayHello=function(){
surperSay.call(_this);
alert("T-hello");
}
return _this;
}
var t=Teacher();
t.sayHello();
*/
/*function Person(name){
var _this={};
_this._name=name;
_this.sayHello=function(){
alert("P-hello"+_this._name);
}
return _this;
}
function Teacher(name){
var _this=Person(name);
var surperSay=_this.sayHello;
_this.sayHello=function(){
surperSay.call(_this);
alert("T-hello"+_this._name);
}
return _this;
}
var t=Teacher("iwen");
t.sayHello();*/
(function(){
var n="ime";
function Person(name){
var _this={};
_this._name=name;
_this.sayHello=function(){
alert("P-hello"+_this._name+n);
}
return _this;
}
window.Person=Person;
}());
function Teacher(name){
var _this=Person(name);
var surperSay=_this.sayHello;
_this.sayHello=function(){
surperSay.call(_this);
alert("T-hello"+_this._name);
}
return _this;
}
var t=Teacher("iwen");
t.sayHello();
JS 面向对象详解的更多相关文章
- Java面向对象详解
Java面向对象详解 前言:接触项目开发也有很长一段时间了,最近开始萌发出想回过头来写写以前学 过的基础知识的想法.一是原来刚开始学习接触编程,一个人跌跌撞撞摸索着往前走,初学的时候很多东西理解的也懵 ...
- js对象详解(JavaScript对象深度剖析,深度理解js对象)
js对象详解(JavaScript对象深度剖析,深度理解js对象) 这算是酝酿很久的一篇文章了. JavaScript作为一个基于对象(没有类的概念)的语言,从入门到精通到放弃一直会被对象这个问题围绕 ...
- java之面向对象详解
#############java面向对象详解#############1.面向对象基本概念2.类与对象3.类和对象的定义格式4.对象与内存分析5.封装性6.构造方法7.this关键字8.值传递与引用 ...
- php开发面试题---php面向对象详解(对象的主要三个特性)
php开发面试题---php面向对象详解(对象的主要三个特性) 一.总结 一句话总结: 对象的行为:可以对 对象施加那些操作,开灯,关灯就是行为. 对象的形态:当施加那些方法是对象如何响应,颜色,尺寸 ...
- C#基础-面向对象详解
面向对象详解 一.什么是面向对象 1>面向对象是一种程序设计思想 2>面向过程和面向对象是什么? 例如要把大象放冰箱怎么做? 面向过程:打开冰箱门->把大象扔进去->关上冰箱门 ...
- Node.js npm 详解
一.npm简介 安装npm请阅读我之前的文章Hello Node中npm安装那一部分,不过只介绍了linux平台,如果是其它平台,有前辈写了更加详细的介绍. npm的全称:Node Package M ...
- Vue.js项目详解
还是以Blog项目来讲解,最近我本人利用闲暇时间,以博客作为参考学习一些新的技术并尝试之前没有尝试过的思路来玩玩. 技术看似枯燥,但是带有一个目的来学,你会发现还是蛮有趣的. 主要实践的就是前后端分离 ...
- 开胃小菜——impress.js代码详解
README 友情提醒,下面有大量代码,由于网页上代码显示都是同一个颜色,所以推荐大家复制到自己的代码编辑器中看. 今天闲来无事,研究了一番impress.js的源码.由于之前研究过jQuery,看i ...
- jquery图片切换插件jquery.cycle.js参数详解
转自:国人的力量 blog.163.com/xz551@126/blog/static/821257972012101541835491/ 自从使用了jquery.cycle.js,我觉得再也不用自己 ...
随机推荐
- 关于mysql 间隙锁
前段时间系统老是出现update死锁,很是纠结.经过排查发现是间隙锁!间隙锁是innodb中行锁的一种, 但是这种锁锁住的却不止一行数据,他锁住的是多行,是一个数据范围.间隙锁的主要作用是为了防止出现 ...
- [think\exception\ErrorException] glob() has been disabled for security reasons
今天同事开发 出现了这个错误 [think\exception\ErrorException] glob() has been disabled for security reasons 打开php. ...
- TCAM CAM 说明 原理 结构 Verilog 硬件实现
TCAM 三态内容地址查找存储器,CAM内容地址查找存储器.区别在于TCAM多了一级掩码功能,也就是说可以指定某几位是dont care.匹配的时候0,1都行的意思. 广泛应用于数据流处理领域,本文简 ...
- Spring启动时获取自定义注解的属性值
1.自定义注解 @Target({ElementType.TYPE, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documen ...
- VMware CentOS Device eth0 does not seem to be present
在VMware里克隆出来的CentOS Linux.. ifconfig...没有看到eth0..然后重启网卡又报下面错误. 故障现象: service network restartShutting ...
- IntelliJ IDEA—IDEA2018.1激活方式
前言 以前用过2015的版本,后面就没有使用了,现在又重新用起来了,突然发现激活好难,通过网上找破解方式,总算找到了一种可以实现破解的方法了.. 破解方式 本人使用的是使用破解补丁的方式实现破解的,此 ...
- asp.net 初级程序员面试题【待续】
C# 常见的排序方式 冒泡排序(Bubble sort) 堆排序(Heap sort) 插入排序(Insertion sort) 归并排序(Merge sort) 快速排序(Quick sort) ...
- window.addEventListener()/window.postMessage(”text“, '*')
1.设置监听 window.addEventListener('message', function (msg) { console.log(msg.data);}) 2.发送 message win ...
- kafka启动报java.net.UnknownHostException
kafka启动报java.net.UnknownHostException 参考资料: 1.https://blog.csdn.net/zdxiq000/article/details/6258765 ...
- 若(p,q)=1,则(p^n,q^n)=1
[若(p,q)=1,则(p^n,q^n)=1] 因(p,q)=1,则p,q可分别表示成如下的形式: p=A^a*B^b*C^c, q=D^d*E^e*F^f 显示ABC.DEF无交集.而p^n.q^n ...