<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> <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> </div>