




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
本章内容实现经典继承原型链使用父方法OOP框架jQuery简单继承经典OOP中的继承如C#,Java或C++经典OOP中的继承当前所有的Student类型实例也是的功能类型,并且有Inheritance继承是一种扩展对象功能给另一个对象的方式如Student继承继承Mammal,等在JavaScript中,继承的实现是由设置派生类型的原型到超类型的实例上function (fname,
lname)
{}function
Student(fname,
lname,
grade)
{}Stotype
=
new
();var
student=new
Student("张","三",5);经典OOP中的继承实现原型链JavaScript中搜索属性的方式原型链JavaScript中的对象只能有单一原型其原型也有原型,以此类推称为原型链当对象上的属性调用时对象搜索该属性如果对象并不包含属性,其原型检查该属性,以此类推如果在原型中都没有找到,结果为undefined调用父方法使用一些OOP的调用父方法JavaScript没有直接的方法调用父方法函数构造器实际上不知道谁是其父调用父方法使用call和apply调用父方法:示例以矩形继承有形状var
Sh =
(function
()
{function
Sh (x,
y)
{//initialize
the
sh}Sh .prototype
=
{serialize:
function
()
{//serialize
the
sh//return
theserialized}};return
Sh
;}());var
Rect
=
(function
()
{function
Rect(x,
y,width,
height)
{Sh .call(this,
x,
y);//初始化矩阵}Rtotype=newSh
();Rtotype.serialize=function(){Sh
.prototype.serialize.call(this);//加入矩阵特定序列化//返回已序列化};returnRect;}());调用父方法:示例以矩形继承有形状var
Sh =
(function
()
{function
Sh (x,
y)
{//initialize
the
sh}Sh .prototype
=
{serialize:
function
()
{//serialize
the
sh//return
theserialized}};return
Sh
;}());var
Rect
=
(function
()
{function
Rect(x,
y,width,
height)
{Sh .call(this,
x,
y);//初始化矩阵}Rtotype=newSh
();Rtotype.serialize=function(){Sh
.prototype.serialize.call(this);//加入矩阵特定序列化//返回已序列化};returnRect;}());调用父构造器调用父方法:示例以矩形继承有形状var
Sh =
(function
()
{function
Sh (x,
y)
{//initialize
the
sh}Sh .prototype
=
{serialize:
function
()
{//serialize
the
sh//return
theserialized}};return
Sh
;}());var
Rect
=
(function
()
{function
Rect(x,
y,width,
height)
{Sh .call(this,
x,
y);//初始化矩阵}Rtotype=newSh
();Rtotype.serialize=function(){Sh
.prototype.serialize.call(this);//加入矩阵特定序列化//返回已序列化};returnRect;}());调用父构造器调用父方法调用父方法演示OOP框架OOP框架OOP是首要设计范式,在大多数编程语言中但,OOP在JavaScript总并不完美同时这也是为什么每个框架都有自己的实现OOP的方式YUI,
Prototype.js,
Backbone.js,等如果不用这些框架,可以用jQuery的简单实现jQuery的简单继承如何用这个?从代码中拷贝创建"class":var
Sh =
Class.extend({init:
function(x,
y){this._x
=
x;this._y
=
y;},serialize:
function(){return
{x:this._x,y:this._y};}});/simple-inheritance继承:var
Rect
=Sh
.extend({init:
function(x,
y,
w,
h){this._super(x,y);this._width
=
w;this._height
=
h;},serialize:
function(){
var
res
=this._super();res.width
=this._width;res.height
=
this._height;returnres;}});jQuery的简单继承this._x=x;this._y=y;/simple-inheritance继承:var
Rect
=Sh
.extend({init:
function(x,
y,
w,
h){this._super(x,y);this._width
=
w;this._height
=
h;},serialize:
function(){
var
res
=this._super();res.width
=this._width;res.height
=
this._height;returnres;}});如何用这个?从代码中拷贝创建"class":var
Sh =
Class.extend({init:
function(x,
y){构造器},serialize:
function(){return
{x:this._x,y:this._y};}});jQuery的简单继承this._x=x;this._y=y;};}});/simple-inheritance继承:var
Rect
=Sh
.extend({init:
function(x,
y,
w,
h){this._super(x,y);this._width
=
w;this._height
=
h;},serialize:
function(){
var
res
=this._super();res.width
=this._width;res.height
=
this._height;returnres;}});如何用这个?从代码中拷贝创建"class":var
Sh =
Class.extend({init:
function(x,
y){构造器},serialize:
function(){return
{x:this._x,y:this._y方法jQuery的简单继承如何用这个?/simple-inheritance从代码中拷贝创建"class":var
Sh =
Class.extend({init:
function(x,
y){this._x
=
x;this._y
=
y;},serialize:
function(){return
{x:this._x,y:this._y};}});继承:var
Rect
=Sh
.extend({init:
function(x,
y,
w,
h){this._super(x,y);this._width
=
w;this._height
=
h;},serialize:
function(){
var
res
=this._super();res.width
=this._width;res.height
=
this._height;returnres;}});构造器方法父构造器jQuery的简单继承如何用这个?/simple-inheritance从代码中拷贝创建"class":var
Sh =
Class.extend({init:
function(x,
y){this._x
=
x;this._y
=
y;},serialize:
function(){return
{x:this._x,y:this._y};}});继承:var
Rect
=Sh
.extend({init:
function(x,
y,
w,
h){this
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 狂犬疫苗使用培训课件
- 点亮校园工程方案(3篇)
- 农业无人机智能化作业环境适应性分析报告2025
- 牧场安全培训模板课件
- 安全教育基地培训教材课件
- 农业保鲜技术革新成果鉴定报告-2025年可持续发展战略
- 礼嘉中学面试题库及答案
- 老板电器ai面试题库及答案
- 安全教育培训费用明细课件
- 开封国企面试题库及答案
- SCI论文的写作与发表课件
- 印刷产品检验报告
- 2022年贵州省人民医院医护人员招聘笔试试题及答案解析
- “数学悖论”-辛普森悖论
- 医疗器械临床试验GCP三套考试题
- 车辆赠与协议模板
- 烧结岗位安全操作培训-PPT课件
- 【课件】1.2 点线传情——造型元素之点线面 课件-2021-2022学年高中美术人美版(2019)选修绘画
- 运动处方(课堂PPT)
- 物资储备与物流方案
- 关于加强铁路企业年金管理的指导意见
评论
0/150
提交评论