<div class="codetitle"> <span><a style="CURSOR: pointer" data="43935" class="copybut" id="copybut43935" onclick="doCopy('code43935')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code43935"> <br> <br> <br> <br><meta charset="UTF-8"> <br><title>Insert title here</title> <br><script type="text/javascript"> <BR>/* <BR>* 组合模式: 构造函数模式+原型模式 <BR>这种方式是javascript中最通用的创建对象的方式 <BR>变量类型属性:用构造函数传递 <BR>函数类型属性:用原型模式声明 <BR>*/ <BR>function Student(name,age){ <BR>this.name=name; <BR>this.age=age; <BR>} <BR>Student.prototype.setName=function(name2){ <BR>this.name=name2; <BR>}; <BR>Student.prototype.getName=function(){ <BR>return this.name; <BR>}; <br><br>var stu1=new Student("小胡",21); <BR>alert(stu1.getName()); <BR></script> <br> <br> <br><br> <br> <br> </div>