function Parent(firstname)
{
this.fname=firstname;
this.age=;
this.sayAge=function()
{
console.log(this.age);
}
}
function Child(firstname)
{
this.parent=Parent;
this.parent(firstname);
delete this.parent;
this.saySomeThing=function()
{
console.log(this.fname);
this.sayAge();
}
}
var mychild=new Child("李");
mychild.saySomeThing();
function Parent(firstname)
{
this.fname=firstname;
this.age=;
this.sayAge=function()
{
console.log(this.age);
}
}
function Child(firstname)
{ this.saySomeThing=function()
{
console.log(this.fname);
this.sayAge();
}
this.getName=function()
{
return firstname;
} }
var child=new Child("张");
Parent.call(child,child.getName());
child.saySomeThing();
function Parent(firstname)
{
this.fname=firstname;
this.age=;
this.sayAge=function()
{
console.log(this.age);
}
}
function Child(firstname)
{ this.saySomeThing=function()
{
console.log(this.fname);
this.sayAge();
}
this.getName=function()
{
return firstname;
} }
var child=new Child("张");
Parent.apply(child,[child.getName()]);
child.saySomeThing();
function Parent()
{ this.sayAge=function()
{
console.log(this.age);
}
}
function Child(firstname)
{
this.fname=firstname;
this.age=;
this.saySomeThing=function()
{
console.log(this.fname);
this.sayAge();
}
} Child.prototype=new Parent();
var child=new Child("张");
child.saySomeThing();
function Parent()
{ this.sayAge=function()
{
console.log(this.age);
}
} Parent.prototype.sayParent=function()
{
alert("this is parentmethod!!!");
} function Child(firstname)
{
Parent.call(this);
this.fname=firstname;
this.age=;
this.saySomeThing=function()
{
console.log(this.fname);
this.sayAge();
}
} Child.prototype=new Parent();
var child=new Child("张");
child.saySomeThing();
child.sayParent();

js实现继承的五种方式的更多相关文章

  1. js实现继承的5种方式 (笔记)

    js实现继承的5种方式 以下 均为 ES5 的写法: js是门灵活的语言,实现一种功能往往有多种做法,ECMAScript没有明确的继承机制,而是通过模仿实现的,根据js语言的本身的特性,js实现继承 ...

  2. js 实现继承的6种方式(逐渐优化)

    <!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...

  3. js 实现继承的几种方式

    //js中实现继承的几种方式 //实现继承首先要有一个父类,先创造一个动物的父类 function Animal(name){ this.name = name; this.shoot = funct ...

  4. 深入浅出js实现继承的7种方式

    给大家介绍7中js继承的方法 有些人认为JavaScript并不是真正的面向对象语言,在经典的面向对象语言中,您可能倾向于定义类对象,然后您可以简单地定义哪些类继承哪些类(参考C++ inherita ...

  5. js实现继承的两种方式

    这是面试时面试官会经常问到问题: js的继承方式大致可分为两种:对象冒充和原型方式: 一.先说对象冒充,又可分为3种:临时属性方式.call().apply(): 1.临时属性方式: 当构造对象son ...

  6. js实现继承的5种方式

    js是门灵活的语言,实现一种功能往往有多种做法,ECMAScript没有明确的继承机制,而是通过模仿实现的,根据js语言的本身的特性,js实现继承有以下通用的几种方式1.使用对象冒充实现继承(该种实现 ...

  7. JavaScript面向对象(三)——继承与闭包、JS实现继承的三种方式

      前  言 JRedu 在之前的两篇博客中,我们详细探讨了JavaScript OOP中的各种知识点(JS OOP基础与JS 中This指向详解 . 成员属性.静态属性.原型属性与JS原型链).今天 ...

  8. JS实现继承的几种方式

    前言 JS作为面向对象的弱类型语言,继承也是其非常强大的特性之一.那么如何在JS中实现继承呢?让我们拭目以待. JS继承的实现方式 既然要实现继承,那么首先我们得有一个父类,代码如下: // 定义一个 ...

  9. js原型继承的几种方式

    1. 原型链继承 2,构造函数继承(对象冒充继承) 3,组合继承(原型链继承+构造函数继承) 4,原型式继承 5. 寄生组合式继承 一.原型链继承 function Show(){ this.name ...

随机推荐

  1. Selenium_Selenium WebDriver 中鼠标和键盘事件分析及扩展

    在使用 Selenium WebDriver 做自动化测试的时候,会经常模拟鼠标和键盘的一些行为.比如使用鼠标单击.双击.右击.拖拽等动作:或者键盘输入.快捷键使用.组合键使用等模拟键盘的操作.在 W ...

  2. Oracle 数值函数

    上一次整理了一下Oracle字符串中常用的函数,接下来就整理一下Oracle数值方面的一些常用的函数. 1.NVL 空值转换函数,请注意一下,任何包含NULL值的算术运算都会得到NULL,这个函数有点 ...

  3. C语言-结构体

    #include<stdio.h> struct stu //定义结构体类型 { int num; char *name; char *sex; float score; } boy[]= ...

  4. Iterator用法

    <% List<Emp> all=DAOFactory.getIEmpDAOInstance().findAll(keyWord); Itrator<Emp> iter= ...

  5. 【androidstudio】将eclipse的项目导入android studio

    一.概述 最近正在实习公司迭代一个app,项目工程比较大,依赖的第三方服务.第三方库较多,比较复杂.因为公司项目一直是在ec上写的,没有android studio的版本.而大家都知道ec写代码远没有 ...

  6. Hadoop.2.x_时间服务器搭建(CentOs6.6)

    一.检查linux系统NTP是否被安装 [liuwl@hadoop09-linux-01 ~]$ [liuwl@hadoop09-linux-01 ~]$ rpm -qa | grep ntp ntp ...

  7. c#面向对象基础 静态成员、构造函数、命名空间与类库

    静态成员 属性.方法和字段等成员是对象实例所特有的,即改变一个对象实例的这些成员不影响其他的实例中的这些成员.除此之外,还有一种静态成员(也称为共享成员),例如静态方法.静态属性或静态字段.静态成员可 ...

  8. 使用powershell提权的一些技巧

    原文:http://fuzzysecurity.com/tutorials/16.html 翻译:http://www.myexception.cn/windows/1752546.html http ...

  9. 模拟状态为active的日志损坏的数据恢复实验(不完全恢复)

    1查看当前日志状态 首先不完全恢复是会丢失数据的,由此在当前打开的数据中我们创建一些测试数据,用来验证当我们进行完不完全恢复后该数据是否还存在. 2模拟删除CURRENT状态的日志 3启动数据验证错误 ...

  10. jquery 多选框的问题

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...