javascript继承
来源:互联网 发布:西安电子科技大学网络 编辑:程序博客网 时间:2024/06/04 01:14
javascript继承
一、对象冒充
1.简单的对象冒充
//简单的对象冒充function Father(name){ this.name=name; this.method= function(){ alert("father method!") }}function Son(name){ this.fatherTemp = Father; this.fatherTemp(name); delete this.fatherTemp;}var son = new Son("son");alert(son.name);son.method();
2.call对象冒充
//使用call、apply方法的对象冒充function Father(name){ this.name=name; this.method=function(){ alert("father method!") }}function Son(name){ Father.call(this,name);}var son = new Son("son")alert(son.name);son.method();
二、原子性的对象冒充
function Father(name){ this.name=name; this.method=function(){ alert("father method!") }}function Son(){}Son.prototype = new Father("father");var son = new Son();alert(son.name);son.method();
三、对象继承的常用方式
function Father(name){ this.name=name;}Father.prototype.method=function(){ alert("father method!")}function Son(name){ Father.call(this,name)}Son.prototype = new Father();Son.prototype.show=function(){ alert("show")}var son = new Son();alert(son.name)son.method();son.show();
阅读全文
0 0
- javascript继承
- javascript继承
- javascript 继承
- Javascript继承
- Javascript继承
- javascript继承
- Javascript继承
- javascript继承
- JavaScript 继承
- javascript 继承
- JavaScript 继承
- javascript 继承
- javascript 继承
- Javascript继承
- Javascript继承
- Javascript 继承
- JavaScript 继承
- javascript继承
- C#学习笔记_3.C#数据类型
- HP Gen8 MicroServer服务器安装WIN7_32位系统
- AB 压力测试工具ApacheBench ab压测参数分析
- 轮播图+小圆点展示
- 90度展示闭合
- javascript继承
- 抓取SAP报表ALV GRID上的数据
- Docker下HBase学习,三部曲之二:集群HBase搭建
- 《TP5.0学习笔记---配置篇》
- MTK6735 硬件资料
- 文章标题
- Android学习路线
- luogu P1095 守望者的逃离
- 安装Eclipse Maven插件的几种方法