zoukankan      html  css  js  c++  java
  • 运用JAVASCRIPT,写一个类,类名:student,他的属性:name,age,tall,他的方法:getName,getAge,getTall


    前几天,看到网上的面试题,自己平时也用js,可一看,傻眼了,用js写类,想想这是很基础的东西,赶紧学习了几天,现在写一下,不对了还请大家指教:
    题目:运用JAVASCRIPT,写一个类,类名:student,他的属性:name,age,tall,他的方法:getName,getAge,getTall

    //首先定义函数
     function student_getName()
        {
            return this.name;
        }
        function student_getAge()
        {
            return this.age;
        }
        function student_getTall()
        {
            return this.tall;
        }
        //定义构造函数
        function student(n,a,t)
        {
            //初始化对象的属性
            this.name=n;
            this.age=a;
            this.tall=t;
            //定义对象的方法
            this.getName=student_getName;
            this.getAge=student_getAge;
            this.getTall=student_getTall;
        }
       function test()
       {
        //首先定义函数
       var s=new student("张三",25,175);
        alert(s.getName());
        alert(s.getAge());
        alert(s.getTall());
        }
  • 相关阅读:
    森林 BZOJ 3123
    calc BZOJ 2655
    修路 BZOJ 4774
    无聊的计算器【数论多合一】
    矩阵乘法 BZOJ 2738
    K大数查询 BZOJ 3110
    发展城市 BZOJ 3700
    降雨量 BZOJ 1067
    chrome中showModalDialog解决方案
    MFC webbrowser读取文档的meta分析
  • 原文地址:https://www.cnblogs.com/zhangzheny/p/617653.html
Copyright © 2011-2022 走看看