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,我觉得再也不用自己 ...
随机推荐
- 正规式->最小化DFA说明
整体的步骤是三步: 一,先把正规式转换为NFA(非确定有穷自动机), 二,在把NFA通过"子集构造法"转化为DFA, 三,在把DFA通过"分割法"进行最小化 ...
- maven 编译解决jdk 版本问题
1.在父工程中pom 添加版本限制: <plugins> <plugin> <groupId>org.apache.maven.plugins</groupI ...
- 「小程序JAVA实战」小程序搜索功能(55)
转自:https://idig8.com/2018/09/23/xiaochengxujavashizhanxiaochengxusousuogongneng54/ 通过用户搜索热销词,将热销词添加到 ...
- proxmox 去除订阅提示
去掉登陆时是否订阅通知修改文件 /usr/share/javascript/proxmox-widget-toolkit/proxmoxlib.js 搜索关键字 “You do not have ...
- Go Flow Control
[Go Flow Control] 1.for没有(),必须有{}. 2.for的前后表达式可以为空. 3.没有while,for即是while. 4.无穷循环. 5.if没有(),必须有{}. 6. ...
- Tomcat 用startup.bat启动,卡住解决
相比较用eclipse发布项目,直接在tomcat的bin目录下用startup.bat启动需要多做一些工作,而且直接运行startup.bat不会报错,不利于解决问题 所以最好的选择是在安装部署时 ...
- CHEMISTS DISCOVER A SAFE, GREEN METHOD TO PROCESS RED PHOSPHORUS
When it comes to making phosphorus compounds, chemists have traditionally relied on w ...
- 15.3Sum (Two-Pointers)
Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all un ...
- Spring分配置文件开发
---------------------siwuxie095 Spring 分配置文件开发 Spring 分配置文件开 ...
- 25- 解决'python -m pip install --upgrade pip' 报错问题
转载于:https://blog.csdn.net/cxs123678/article/details/80659273 再安装包的时候提示 You are using pip version 9.0 ...