javascript中apply

来源:互联网 发布:双色球旋转矩阵工具 编辑:程序博客网 时间:2024/05/29 04:56

在方法中想用到另外一个对象的方法可以用apply:

<html><head><!--    <script src="jquery.js">    --><script type="text/javascript"></script><script>    function Person(name ,age)    {    this.name=name;    this.age=age;    }    function Student(name,age,grade)    {    Person.apply(this,arguments);    this.grade=grade;    }    var student=new Student("qian",21,"firs grade");    console.log("name"+student.name+'\n'+"age"+student.age+'\n'+student.grade+'\n');</script></head><body></body></html>


这里 Student用到了Person中的name和age方法


原创粉丝点击