zoukankan      html  css  js  c++  java
  • js继承

    1.apply继承

    function Anmail(name,age){
    this.name=name;
    this.age=age;
    this.eat=function(){
    alert("Ok")
    }
    }

    function dog(name,age){
    Anmail.apply(this, [name,age])
    }

    var d=new dog();
    d.eat()

    2.原型继承

    function Anmail(name,age){
    this.name=name;
    this.age=age;
    this.eat=function(){
    alert("Ok")
    }
    }

    function dog(name,age){
    Anmail.apply(this, [name,age])
    }
    dog.prototype=Anmail;
    var d=new dog();
    d.eat()

    2.多态

    <%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Insert title here</title>
    </head>
    <body>

    </body>
    <script type="text/javascript">
    function amil() {
    this.say = function() {
    alert("dongwu");
    }
    }

    function dog() {
    this.say = function() {
    alert("dog");
    }
    dog.prototype=new amil();
    }
    function cat() {
    this.say = function() {
    alert("cat");
    }
    }
    cat.prototype=new cat();
    function say(anm) {
    if(anm instanceof amil){
    anm.say;
    }
    }
    var d=new dog();
    say(d);
    </script>
    </html>

  • 相关阅读:
    JVM原理---------------1.开篇
    mysql开启事务的方式,命令学习
    mysql中的锁
    mysql索引底层原理
    mysql的常见存储引擎与常见日志类型,以及4种线程的作用
    Mutex
    委托和匿名委托
    线程通信
    同步锁
    [ValidateInput(false)]
  • 原文地址:https://www.cnblogs.com/javaweb2/p/6263700.html
Copyright © 2011-2022 走看看