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());
        }
  • 相关阅读:
    Beta 冲刺(4/7)
    Beta 冲刺(3/7)
    Beta 冲刺(2/7)
    福大软工 · 最终作业
    福大软工 · 第十二次作业
    Beta 冲刺(7/7)
    Beta 冲刺(6/7)
    Beta 冲刺(5/7)
    Beta 冲刺(4/7)
    Beta 冲刺(3/7)
  • 原文地址:https://www.cnblogs.com/zhangzheny/p/617653.html
Copyright © 2011-2022 走看看