JavaScript資料型,對象,建構函數,原型對象,初識原型鏈,物件繼承
一。單字部分
①object父類別②constructor建構子③instance實例④call呼叫
⑤apply應用⑥combination組合⑦inheritance繼承
二.預習部分
1.簡述創建物件的兩種方法,以及兩者的區別
new 和字面量賦值
前者要用點.加入屬性與方法
後者直接呼叫
2.簡述使用建構子建立實例的步驟
①建立一個新物件
②將建構函式的作用域賦值給新物件
③執行建構函式程式碼區塊
④傳回新物件
#3.簡述原型鏈在繼承中的作用
它是實作繼承的主要方法
三.上機部分
1.建立person物件
#lang="en"> | |
# | ## |
charset="UTF-8"> | |
## | |
# | |
# | id="aa"> |
<script> </td> </tr> <tr> <td class="line-number"></td># <td class="line-content">##var createTi=document.createElement("p" );</td> </tr> <tr> <td class="line-number"> </td> <td class="line-content">var person=new Object();</td> </tr> <tr> <td class="line-number"> </td> <td class="line-content">person.name= "郎曉明";</td> </tr> <tr> <td class="line-number"> </td> <td class="line-content">person.age="38";</td> </tr> <tr> <td class="line-number"> </td> <td class="line-content">person. job="中國內地男演員、歌手";</td> </tr> <tr> <td class="line-number"> </td> <td class="line-content">person.address="中國北京海淀區";</td> </tr> <tr> <td class="line-number"> </td> <td class="line-content">person.info=function () {</td> </tr> <tr> <td class="line-number"># </td> <td class="line-content">var strr="姓名:"+this.name+"<br/ >年齡:"+this.age+"<br/>工作:"+this.job+"<br/>住址:"+this.address;</td> </tr> <tr> <td class="line-number"> </td> <td class="line-content">//document.write(strr);</td> </tr> <tr> <td class="line-number"> </td> <td class="line-content">document.getElementById("aa").innerHTML=strr;</td> </tr> <tr> <td class="line-number"># </td> <td class="line-content">}</td> </tr> <tr> <td class="line-number"> </td> <td class="line-content">person.info();</td> </tr> <tr> <td class="line-number"> # </td> <td class="line-content"><span class="html-tag"></script> | |
# | |
# |
2.创建person构造函数
lang="en"> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
charset="UTF-8"> | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
id="aa"> |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
o | #<script> </span></td>
</tr>
<tr>
<td class="line-number"></td>
<td class="line-content"></td>
</tr>
<tr>
<td class="line-number"> </td> <td class="line-content"></td>function Person(name,age,job,address) {</tr>
<tr>
<td class="line-number"></td> <td class="line-content"></td>this.name=name;</tr>
<tr> <td class="line-number"></td># <td class="line-content"></td>this.age=age;</tr>
<tr>
<td class="line-number"></td># <td class="line-content"></td>this.job=job;</tr>
<tr>
<td class="line-number"></td> <td class="line-content"></td>this.address=address;</tr>
<tr>
<td class="line-number"></td># <td class="line-content"></td>this.show=function() {</tr>
<tr>
<td class="line-number"></td>
<td class="line-content"></td>
</tr>
<tr>
<td class="line-number"></td>
<td class="line-content"></td>
</tr>
<tr>
<td class="line-number"></td>
<td class="line-content"></td>
</tr>
<tr>
<td class="line-number"></td>
<td class="line-content"></td>
</tr>
<tr>
<td class="line-number"></td>
<td class="line-content"></td>
</tr>
<tr># <td class="line-number"></td>var createTi=document.createElement("p");<td class="line-content"></td>
</tr>
<tr> <td class="line-number"></td>var strr="姓名:"+this .name+"<br/>年齡:"+this.age+"<br/>工作:"+this.job+"<br/>住址:"+this.address;<td class="line-content"></td>
</tr>
<tr> <td class="line-number"></td>document.getElementById("aa").innerHTML=strr;<td class="line-content"></td>
</tr>
<tr> <td class="line-number"></td>##}<td class="line-content"></td>
</tr>
<tr> <td class="line-number"></td>}<td class="line-content"></td>
</tr>
<tr> <td class="line-number"></td>function Pers(){<td class="line-content"></td>
</tr>
<tr> <td class="line-number"></td> <td class="line-content"></td>
</tr>
<tr> <td class="line-number"></td> <td class="line-content"></td>
</tr>
<tr># <td class="line-number"></td>}<td class="line-content"></td>
</tr>
<tr>
<td class="line-number"></td>
<td class="line-content"></td>
</tr>
<tr>
<td class="line-number"></td>
<td class="line-content"></td>
</tr>
<tr>
<td class="line-number"></td>
<td class="line-content"></td>
</tr>
<tr>
<td class="line-number"></td>
<td class="line-content"></td>
</tr>
<tr>
<td class="line-number"></td>
<td class="line-content"></td>
</tr>
<tr>
<td class="line-number"></td>
<td class="line-content">## </td>
</tr>//var newper=new Person("郎明明","38","中國內地男演員、歌手","中國北京海淀區");<tr>
<td class="line-number"></td>
<td class="line-content"># </td>
</tr>Pers.prototype.name1="陳東";<tr>
<td class="line-number"></td>
<td class="line-content"> <span class="html-tag"></span>Pers.prototype.age1="20"; </td>
</tr>
<tr>
<td class="line-number"> </td>
<td class="line-content">Pers.prototype.job1="IT";<span class="html-tag"></span>
</td>
</tr> <tr>
<td class="line-number">Pers.prototype. address1="河南省";</td>
<td class="line-content">
<span class="html-tag"></span> </td>
</tr>Pers.prototype.showinn=function () {</tbody></table>###### ### ###var createTi=document.createElement("p");############# ######var strrr="姓名:"+this.name1+"<br/> ;年齡:"+this.age1+"<br/>工作:"+this.job1+"<br/>住址:"+this.address1;############# # #####document.getElementById("aa").innerHTML=strrr;############ ######}############# # #####var one=new Pers();############ ######one.showinn();############ # #####//newper.show();############ ##########</script> ########### #### ######### ################ ############ ############
3.创建person对象原型链
以上是js中資料類型,對象,建構函數詳解的詳細內容。更多資訊請關注PHP中文網其他相關文章! 陳述: 本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn |