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>

  • 相关阅读:
    HTML特效代码大全
    PHP网站加网站访问量统计
    定时显示隐藏
    加入收藏 设为首页
    IP和归属地
    手机站的拨打电话和发短信
    Shell运算
    Shell命令替换与变量替换
    $* 和 $@ 的区别
    Shell特殊变量列表
  • 原文地址:https://www.cnblogs.com/javaweb2/p/6263700.html
Copyright © 2011-2022 走看看