• 继承人人前端笔试题


    请使用javascript模拟对象,创建Person类,要求有姓名和年龄属性,然后使用继承实现Programmer类,要求有姓名、年龄、性别以及掌握的 语言属性。

    以下为实现代码(此类继承用的是原型链实现):

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>New Web Project</title>
            <style type="text/css">
                span{
                    color: #66A300;
                    font-family: "Arial Black";
                }
            </style>
        </head>
        <body>
             <div id="main">
                 <span>hello!</span>
             </div>
             
             <script type="text/javascript">
        
                 function Person(name,age){
                     this.name = name;
                     this.age = age;
                 }
                 
                 function Programmer(name,age,sex,language){
                     Person.call(this,name,age);//继承类的构造函数
                     this.sex = sex;
                     this.language = language;
                 }
                 
                 //设置原型链
                 Programmer.prototype = new Person();
                 Programmer.prototype.constructor = Programmer;
                 Programmer.prototype.getName = function(){
                     return this.name;
                 }
                 
                 
                 var smirk = new Programmer("zy",21,"f","ENGLISH");
                 alert(smirk.getName());
                 
    
    
             </script>
        </body>
    </html>
  • 相关阅读:
    发布镜像
    实战Tomcat镜像
    Docker File介绍
    数据卷容器
    DockerFile
    具名、匿名、指定路径挂载
    实战MySQL
    SHELL 常用技巧
    CentOS6和7启动流程
    解决服务器openssh漏洞
  • 原文地址:https://www.cnblogs.com/yingsmirk/p/2438935.html
Copyright © 2020-2023  润新知